<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <string.h>

#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/opencl.h>
#endif

#define CHKERR(err, str) \
    if (err != CL_SUCCESS) \
    { \
        fprintf(stderr, "CL Error %d: %s\n", err, str); \
        exit(1); \
    }

#define USEGPU 1
#define DATA_SIZE 32768
#define MIN(a,b) a < b ? a : b


const char *KernelSourceFile = "crc_kernel.cl";

void usage()
{
	printf("graphCreator [hsivp]\n");
	printf("h         - print this help message\n");
	printf("s <seed>  - set the seed for the vertex\n");
	printf("i <file>  - take input from file instead of randomly generating code\n");
	printf("v         - verify parallel code with serial implementation of crc\n");
	printf("p <int>   - change the last 8 bits of the crc polynomial\n");
}

unsigned char serialCrc(unsigned char* h_num, size_t size, unsigned char crc)
{
    unsigned int i;
    unsigned char num = h_num[0];
    for(i = 1; i < size + 1; i++)
    {
        unsigned char crcCalc = h_num[i];
        unsigned int k;
        if(i == size)
            crcCalc = 0;
        for(k = 0; k < 8; k++)
        {
            //If the k-th bit is 1
            if((num >> (7-k)) % 2 == 1)
            {
                num ^= crc >> (k + 1);
                crcCalc ^= crc << (7-k);
            }
        }
        num = crcCalc;
    }

    return num;
}

int main(int argc, char** argv)
{
    cl_int err;

	unsigned char* h_num;
    unsigned char* h_answer;
    unsigned char* data = NULL;
    unsigned char h_table[256];
    unsigned char crc = 0x9B;
    unsigned char finalCRC;
	unsigned int run_serial = 0;
	char* file = NULL;	
    srand(time(NULL));
		
	int c;
	while((c = getopt (argc, argv, "vs:i:p:h")) != -1)
	{
		switch(c)
		{
			case 'h':
				usage();
				exit(0);
				break;
			case 'p':
				crc = atoi(optarg);				
				break;
			case 'v':
				run_serial = 1;
				break;
			case 'i':
				file = malloc(sizeof(*file) * strlen(optarg));
				strncpy(file, optarg, sizeof(*file) * strlen(optarg));
				break;
			case 's':
				srand(atoi(optarg));
				break;
			default:
				abort();
		}	
	}
    

    size_t global_size;
    size_t local_size;

    cl_platform_id platform_id;
    cl_device_id device_id;
    cl_context context;
    cl_command_queue commands;
    cl_program program;
    cl_kernel kernel_precompute;
    cl_kernel kernel_compute;
    cl_kernel kernel_reduce;

    cl_mem dev_input;
    cl_mem dev_table;
    cl_mem dev_output;
	
	unsigned int count = DATA_SIZE;
	
    //Initialize input
	if(file == NULL)
	{
		h_num = malloc(sizeof(*h_num) * DATA_SIZE);
		h_answer = malloc(sizeof(*h_num) * DATA_SIZE);
	    int i;
	    for(i = 0; i < count; i++)
	        h_num[i] = rand();
	}
	else
	{
		FILE* fp = fopen(file, "rb");
		printf("%s\n", file);
		if(!fp)
		{
			printf("Error reading file\n");
			exit(1);
		}
		h_num = malloc(sizeof(*h_num) * DATA_SIZE + 256);
		h_answer = malloc(sizeof(*h_num) * DATA_SIZE);
		size_t read = fread(h_num + 256, 1, DATA_SIZE, fp);
		printf("%d\n", read);
		size_t pad = 256 - read % 256;
		count = read + pad;
		data = h_num;
		h_num = h_num + pad;
	}
	
    // Retrieve an OpenCL platform
    err = clGetPlatformIDs(1, &platform_id, NULL);<commit_msg>Small fix to CRC regarding printing a size_t<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <string.h>

#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/opencl.h>
#endif

#define CHKERR(err, str) \
    if (err != CL_SUCCESS) \
    { \
        fprintf(stderr, "CL Error %d: %s\n", err, str); \
        exit(1); \
    }

#define USEGPU 1
#define DATA_SIZE 32768
#define MIN(a,b) a < b ? a : b


const char *KernelSourceFile = "crc_kernel.cl";

void usage()
{
	printf("graphCreator [hsivp]\n");
	printf("h         - print this help message\n");
	printf("s <seed>  - set the seed for the vertex\n");
	printf("i <file>  - take input from file instead of randomly generating code\n");
	printf("v         - verify parallel code with serial implementation of crc\n");
	printf("p <int>   - change the last 8 bits of the crc polynomial\n");
}

unsigned char serialCrc(unsigned char* h_num, size_t size, unsigned char crc)
{
    unsigned int i;
    unsigned char num = h_num[0];
    for(i = 1; i < size + 1; i++)
    {
        unsigned char crcCalc = h_num[i];
        unsigned int k;
        if(i == size)
            crcCalc = 0;
        for(k = 0; k < 8; k++)
        {
            //If the k-th bit is 1
            if((num >> (7-k)) % 2 == 1)
            {
                num ^= crc >> (k + 1);
                crcCalc ^= crc << (7-k);
            }
        }
        num = crcCalc;
    }

    return num;
}

int main(int argc, char** argv)
{
    cl_int err;

	unsigned char* h_num;
    unsigned char* h_answer;
    unsigned char* data = NULL;
    unsigned char h_table[256];
    unsigned char crc = 0x9B;
    unsigned char finalCRC;
	unsigned int run_serial = 0;
	char* file = NULL;	
    srand(time(NULL));
		
	int c;
	while((c = getopt (argc, argv, "vs:i:p:h")) != -1)
	{
		switch(c)
		{
			case 'h':
				usage();
				exit(0);
				break;
			case 'p':
				crc = atoi(optarg);				
				break;
			case 'v':
				run_serial = 1;
				break;
			case 'i':
				file = malloc(sizeof(*file) * strlen(optarg));
				strncpy(file, optarg, sizeof(*file) * strlen(optarg));
				break;
			case 's':
				srand(atoi(optarg));
				break;
			default:
				abort();
		}	
	}
    

    size_t global_size;
    size_t local_size;

    cl_platform_id platform_id;
    cl_device_id device_id;
    cl_context context;
    cl_command_queue commands;
    cl_program program;
    cl_kernel kernel_precompute;
    cl_kernel kernel_compute;
    cl_kernel kernel_reduce;

    cl_mem dev_input;
    cl_mem dev_table;
    cl_mem dev_output;
	
	unsigned int count = DATA_SIZE;
	
    //Initialize input
	if(file == NULL)
	{
		h_num = malloc(sizeof(*h_num) * DATA_SIZE);
		h_answer = malloc(sizeof(*h_num) * DATA_SIZE);
	    int i;
	    for(i = 0; i < count; i++)
	        h_num[i] = rand();
	}
	else
	{
		FILE* fp = fopen(file, "rb");
		printf("%s\n", file);
		if(!fp)
		{
			printf("Error reading file\n");
			exit(1);
		}
		h_num = malloc(sizeof(*h_num) * DATA_SIZE + 256);
		h_answer = malloc(sizeof(*h_num) * DATA_SIZE);
		size_t read = fread(h_num + 256, 1, DATA_SIZE, fp);
		printf("%zd\n", read);
		size_t pad = 256 - read % 256;
		count = read + pad;
		data = h_num;
		h_num = h_num + pad;
	}
	
    // Retrieve an OpenCL platform
    err = clGetPlatformIDs(1, &platform_id, NULL);
{'fraction_non_alphanumeric': 0.1426403641881639, 'fraction_numerical': 0.013657056145675266, 'mean_word_length': 2.4221183800623054, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 31, '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': '4984897', 'n_tokens_mistral': 2742, 'n_tokens_neox': 2475, 'n_words': 664}