0% found this document useful (0 votes)
46 views

Source - Size Fread (Source - STR, 1, MAX - SOURCE - SIZE, FP) : "Sort - Desc"

This C code loads an OpenCL kernel from a file called "sort.cl", creates an OpenCL context and program, builds the program, and creates a kernel called "sort_desc". It then releases the kernel, program, and command queue before ending. The code is setting up an OpenCL environment to execute an OpenCL kernel for sorting.

Uploaded by

sindhura2258
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Source - Size Fread (Source - STR, 1, MAX - SOURCE - SIZE, FP) : "Sort - Desc"

This C code loads an OpenCL kernel from a file called "sort.cl", creates an OpenCL context and program, builds the program, and creates a kernel called "sort_desc". It then releases the kernel, program, and command queue before ending. The code is setting up an OpenCL environment to execute an OpenCL kernel for sorting.

Uploaded by

sindhura2258
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>
#include <stdlib.h>
#include <CL/cl.h>
#include<string.h>
#define MAX_SOURCE_SIZE (0x100000)

int main(void)
{



FILE *fp; char *source_str; size_t source_size;

fp = fopen("sort.cl", "r");
if (!fp) {
fprintf(stderr, "Failed to load kernel.\n"); exit(1);
}
source_str = (char*)malloc(MAX_SOURCE_SIZE);
source_size = fread( source_str, 1, MAX_SOURCE_SIZE, fp);

fclose( fp );

cl_platform_id platform_id = NULL; cl_device_id device_id = NULL;
cl_uint ret_num_devices; cl_uint ret_num_platforms;

cl_int ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
ret = clGetDeviceIDs( platform_id, CL_DEVICE_TYPE_GPU, 1,&device_id,
&ret_num_devices);
cl_context context = clCreateContext( NULL, 1, &device_id, NULL, NULL, &ret);





cl_program program = clCreateProgramWithSource(context, 1,(const char **)&source_str,
(const size_t *)&source_size, &ret);
ret = clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);
cl_kernel kernel = clCreateKernel(program, "sort_desc", &ret);



ret = clReleaseKernel(kernel);
ret = clReleaseProgram(program);
clReleaseCommandQueue(command_queue);

}

You might also like