<commit_before>#include <stdio.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#include <perf_counter.h>

#include <nnpack.h>

extern unsigned long long median(unsigned long long array[], size_t length);
extern struct nnp_profile median_profile(struct nnp_profile array[], size_t length);
extern void read_memory(const void* memory, size_t length);

enum mode {
	mode_output,
	mode_input_gradient,
	mode_kernel_gradient,
	mode_inference,
};

struct nnp_profile benchmark_convolution(
	enum mode mode,
	const void* memory, size_t cache_size,
	enum nnp_convolution_algorithm algorithm,
	enum nnp_convolution_transform_strategy transform_strategy,
	size_t batch_size,
	size_t input_channels,
	size_t output_channels,
	struct nnp_size input_size,
	struct nnp_padding input_padding,
	struct nnp_size kernel_size,
	struct nnp_size output_subsampling,
	float input[],
	float kernel[],
	const float bias[],
	float output[],
	pthreadpool_t threadpool,
	size_t max_iterations)
{
	struct nnp_profile computation_profile[max_iterations];
	for (size_t iteration = 0; iteration < max_iterations; iteration++) {
		read_memory(memory, cache_size);
		switch (mode) {
			case mode_output:
				nnp_convolution_output(
					algorithm,
					batch_size,
					input_channels,
					output_channels,
					input_size,
					input_padding,
					kernel_size,
					input,
					kernel,
					bias,
					output,
					threadpool,
					&computation_profile[iteration]);
				break;
			case mode_input_gradient:
				nnp_convolution_input_gradient(
					algorithm,
					batch_size,
					input_channels,
					output_channels,
					input_size,
					input_padding,
					kernel_size,
					output,
					kernel,
					input,
					threadpool,
					&computation_profile[iteration]);
				break;
			case mode_kernel_gradient:
				nnp_convolution_kernel_gradient(
					algorithm,
					batch_size,
					input_channels,
					output_channels,
					input_size,
					input_padding,
					kernel_size,
					input,
					output,
					kernel,
					threadpool,
					&computation_profile[iteration]);
				break;
			case mode_inference:
				nnp_convolution_inference(
					algorithm,
					transform_strategy,
					input_channels,
					output_channels,
					input_size,
					input_padding,
					kernel_size,
					output_subsampling,
					input,
					kernel,
					bias,
					output,
					threadpool,
					&computation_profile[iteration]);
				break;
		}
	}
	return median_profile(computation_profile, max_iterations);
}

struct options {
	enum mode mode;
	size_t batch_size;
	size_t input_channels;
	size_t output_channels;
	struct nnp_size input_size;
	size_t input_padding;
	struct nnp_size kernel_size;
	struct nnp_size output_subsampling;
	enum nnp_convolution_algorithm algorithm;
	enum nnp_convolution_transform_strategy transform_strategy;
	size_t threads;
	size_t iterations;
	bool threadpool;
};

static void print_options_help(const char* program_name) {
	printf(
"%s parameters...\n"
"Required parameters:\n"
"  -ic  --input-channels     The number of input channels\n"
"  -oc  --output-channels    The number of output channels\n"
"  -is  --input-size         Input height and width\n"
"  -os  --kernel-size        Kernel height and width\n"
"Optional parameters:\n"
"  -m   --mode               The convolution mode (output, inference)\n"
"  -a   --algorithm          The algorithm (auto, ft8x8, ft16x16, wt8x8, or implicit-gemm) for computing convolution (default: auto)\n"
"  -s   --strategy           The transform strategy (block, tuple, precompute) in inference mode (default: tuple)\n"
"  -b   --batch              The size of a minibatch (default: 1)\n"
"       --output-subsampling The size of a output subsampling region (default: 1x1)\n"
"  -ip  --padding            Implicit input padding (default: 0)\n"
"  -t   --threads            The number of threads (default: all; 0 to disable threadpool)\n"
"  -i   --iterations         # iterations (default: 3)\n",
		program_name);
}

static struct options parse_options(int argc, char** argv) {<commit_msg>Benchmarks: fix help in convolution benchmark<commit_after>#include <stdio.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#include <perf_counter.h>

#include <nnpack.h>

extern unsigned long long median(unsigned long long array[], size_t length);
extern struct nnp_profile median_profile(struct nnp_profile array[], size_t length);
extern void read_memory(const void* memory, size_t length);

enum mode {
	mode_output,
	mode_input_gradient,
	mode_kernel_gradient,
	mode_inference,
};

struct nnp_profile benchmark_convolution(
	enum mode mode,
	const void* memory, size_t cache_size,
	enum nnp_convolution_algorithm algorithm,
	enum nnp_convolution_transform_strategy transform_strategy,
	size_t batch_size,
	size_t input_channels,
	size_t output_channels,
	struct nnp_size input_size,
	struct nnp_padding input_padding,
	struct nnp_size kernel_size,
	struct nnp_size output_subsampling,
	float input[],
	float kernel[],
	const float bias[],
	float output[],
	pthreadpool_t threadpool,
	size_t max_iterations)
{
	struct nnp_profile computation_profile[max_iterations];
	for (size_t iteration = 0; iteration < max_iterations; iteration++) {
		read_memory(memory, cache_size);
		switch (mode) {
			case mode_output:
				nnp_convolution_output(
					algorithm,
					batch_size,
					input_channels,
					output_channels,
					input_size,
					input_padding,
					kernel_size,
					input,
					kernel,
					bias,
					output,
					threadpool,
					&computation_profile[iteration]);
				break;
			case mode_input_gradient:
				nnp_convolution_input_gradient(
					algorithm,
					batch_size,
					input_channels,
					output_channels,
					input_size,
					input_padding,
					kernel_size,
					output,
					kernel,
					input,
					threadpool,
					&computation_profile[iteration]);
				break;
			case mode_kernel_gradient:
				nnp_convolution_kernel_gradient(
					algorithm,
					batch_size,
					input_channels,
					output_channels,
					input_size,
					input_padding,
					kernel_size,
					input,
					output,
					kernel,
					threadpool,
					&computation_profile[iteration]);
				break;
			case mode_inference:
				nnp_convolution_inference(
					algorithm,
					transform_strategy,
					input_channels,
					output_channels,
					input_size,
					input_padding,
					kernel_size,
					output_subsampling,
					input,
					kernel,
					bias,
					output,
					threadpool,
					&computation_profile[iteration]);
				break;
		}
	}
	return median_profile(computation_profile, max_iterations);
}

struct options {
	enum mode mode;
	size_t batch_size;
	size_t input_channels;
	size_t output_channels;
	struct nnp_size input_size;
	size_t input_padding;
	struct nnp_size kernel_size;
	struct nnp_size output_subsampling;
	enum nnp_convolution_algorithm algorithm;
	enum nnp_convolution_transform_strategy transform_strategy;
	size_t threads;
	size_t iterations;
	bool threadpool;
};

static void print_options_help(const char* program_name) {
	printf(
"%s parameters...\n"
"Required parameters:\n"
"  -ic  --input-channels     The number of input channels\n"
"  -oc  --output-channels    The number of output channels\n"
"  -is  --input-size         Input height and width\n"
"  -ks  --kernel-size        Kernel height and width\n"
"Optional parameters:\n"
"  -m   --mode               The convolution mode (output, inference, input-gradient, kernel-gradient)\n"
"  -a   --algorithm          The algorithm (auto, ft8x8, ft16x16, wt8x8, or implicit-gemm) for computing convolution (default: auto)\n"
"  -s   --strategy           The transform strategy (block, tuple, precompute) in inference mode (default: tuple)\n"
"  -b   --batch              The size of a minibatch (default: 1)\n"
"       --output-subsampling The size of a output subsampling region (default: 1x1)\n"
"  -ip  --padding            Implicit input padding (default: 0)\n"
"  -t   --threads            The number of threads (default: all; 0 to disable threadpool)\n"
"  -i   --iterations         # iterations (default: 3)\n",
		program_name);
}

static struct options parse_options(int argc, char** argv) {
{'fraction_non_alphanumeric': 0.08649505916798829, 'fraction_numerical': 0.003659875564230816, 'mean_word_length': 3.445770065075922, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1733579', 'n_tokens_mistral': 3161, 'n_tokens_neox': 2624, 'n_words': 681}