int main(void){ cl_int err; cl_context context; cl_device_id did; cl_command_queue queue; CHECK_CL_ERROR(poclu_get_any_device(&context, &did, &queue)); TEST_ASSERT( context ); TEST_ASSERT( did ); TEST_ASSERT( queue ); size_t program_size = strlen(program_src); char* program_buffer = program_src; cl_program program = clCreateProgramWithSource(context, 1, (const char**)&program_buffer, &program_size, &err); //clCreateProgramWithSource for the program with #include failed CHECK_OPENCL_ERROR_IN("clCreateProgramWithSource"); err = clBuildProgram(program, 1, &did, NULL, NULL, NULL); TEST_ASSERT(err == CL_BUILD_PROGRAM_FAILURE); CHECK_CL_ERROR (clReleaseCommandQueue (queue)); CHECK_CL_ERROR (clReleaseProgram (program)); CHECK_CL_ERROR (clReleaseContext (context)); CHECK_CL_ERROR (clUnloadCompiler ()); return EXIT_SUCCESS; }
int main(int argc, char **argv) { cl_int err; const char *krn_src; cl_program empty, program; cl_context ctx; cl_device_id did; cl_command_queue queue; cl_uint num_krn; cl_kernel kernels[2]; poclu_get_any_device(&ctx, &did, &queue); TEST_ASSERT( ctx ); TEST_ASSERT( did ); TEST_ASSERT( queue ); /* Test creating a program from an empty source */ empty = clCreateProgramWithSource(ctx, 1, &empty_src, NULL, &err); CHECK_OPENCL_ERROR_IN("clCreateProgramWithSource"); err = clBuildProgram(empty, 0, NULL, NULL, NULL, NULL); CHECK_OPENCL_ERROR_IN("clBuildProgram"); err = clCreateKernelsInProgram(empty, 0, NULL, &num_krn); CHECK_OPENCL_ERROR_IN("clCreateKernelsInProgram"); TEST_ASSERT(num_krn == 0); krn_src = poclu_read_file(SRCDIR "/tests/runtime/test_clCreateKernelsInProgram.cl"); TEST_ASSERT(krn_src); program = clCreateProgramWithSource(ctx, 1, &krn_src, NULL, &err); CHECK_OPENCL_ERROR_IN("clCreateProgramWithSource"); err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL); CHECK_OPENCL_ERROR_IN("clBuildProgram"); err = clCreateKernelsInProgram(program, 0, NULL, &num_krn); CHECK_OPENCL_ERROR_IN("clCreateKernelsInProgram"); // test_clCreateKernelsInProgram.cl has two kernel functions. TEST_ASSERT(num_krn == 2); err = clCreateKernelsInProgram(program, 2, kernels, NULL); CHECK_OPENCL_ERROR_IN("clCreateKernelsInProgram"); // make sure the kernels were actually created // Note: nothing in the specification says which kernel function // is kernels[0], which is kernels[1]. For now assume pocl/LLVM // orders these deterministacally err = clEnqueueTask(queue, kernels[0], 0, NULL, NULL); CHECK_OPENCL_ERROR_IN("clEnqueueTask"); err = clFinish(queue); CHECK_OPENCL_ERROR_IN("clFinish"); err = clEnqueueTask(queue, kernels[1], 0, NULL, NULL); CHECK_OPENCL_ERROR_IN("clEnqueueTask"); err = clFinish(queue); CHECK_OPENCL_ERROR_IN("clFinish"); return EXIT_SUCCESS; }
int main() { cl_int err; cl_event user_evt = NULL; int i; // An user event can be set to either complete or a negative value, indicating error; // additionally, no objects involved in a command that waits on the user event should // be released before the event status is set; however, it should be possible to release // everything even if the status is set to something which is NOT CL_COMPLETE. So // try both CL_COMPLETE and a negative value cl_int status[] = {CL_INVALID_EVENT, CL_COMPLETE }; // We also query for profiling info of the event, which according to the standard // should return CL_PROFILING_INFO_NOT_AVAILABLE cl_ulong queued, submitted, started, endtime; for (i = 0; i < ARRAY_SIZE(status); ++i) { cl_context context; cl_command_queue queue; cl_device_id device; CHECK_CL_ERROR(poclu_get_any_device(&context, &device, &queue)); TEST_ASSERT( context ); TEST_ASSERT( device ); TEST_ASSERT( queue ); user_evt = clCreateUserEvent(context, &err); CHECK_OPENCL_ERROR_IN("clCreateUserEvent"); TEST_ASSERT( user_evt ); CHECK_CL_ERROR(clSetUserEventStatus(user_evt, status[i])); err = clGetEventProfilingInfo(user_evt, CL_PROFILING_COMMAND_QUEUED, sizeof(queued), &queued, NULL); TEST_ASSERT(err == CL_PROFILING_INFO_NOT_AVAILABLE); err = clGetEventProfilingInfo(user_evt, CL_PROFILING_COMMAND_SUBMIT, sizeof(submitted), &submitted, NULL); TEST_ASSERT(err == CL_PROFILING_INFO_NOT_AVAILABLE); err = clGetEventProfilingInfo(user_evt, CL_PROFILING_COMMAND_START, sizeof(started), &started, NULL); TEST_ASSERT(err == CL_PROFILING_INFO_NOT_AVAILABLE); err = clGetEventProfilingInfo(user_evt, CL_PROFILING_COMMAND_END, sizeof(endtime), &endtime, NULL); TEST_ASSERT(err == CL_PROFILING_INFO_NOT_AVAILABLE); CHECK_CL_ERROR(clReleaseEvent(user_evt)); CHECK_CL_ERROR(clReleaseCommandQueue(queue)); CHECK_CL_ERROR(clReleaseContext(context)); } return EXIT_SUCCESS; }
int main(int argc, char **argv) { cl_int err; const char *krn_src; cl_program program; cl_context ctx; cl_device_id did; cl_command_queue queue; cl_uint num_krn; cl_kernel kernels[2]; poclu_get_any_device(&ctx, &did, &queue); assert( ctx ); assert( did ); assert( queue ); krn_src = poclu_read_file(SRCDIR "/tests/runtime/test_clCreateKernelsInProgram.cl"); assert(krn_src); program = clCreateProgramWithSource(ctx, 1, &krn_src, NULL, NULL); err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL); assert(err == CL_SUCCESS); err = clCreateKernelsInProgram(program, 0, NULL, &num_krn); assert(err == CL_SUCCESS); // test_clCreateKernelsInProgram.cl has two kernel functions. assert(num_krn == 2); err = clCreateKernelsInProgram(program, 2, kernels, NULL); assert(err == CL_SUCCESS); // make sure the kernels were actually created // Note: nothing in the specification says which kernel function // is kernels[0], which is kernels[1]. For now assume pocl/LLVM // orders these deterministacally err = clEnqueueTask(queue, kernels[0], 0, NULL, NULL); assert(err == CL_SUCCESS); err = clEnqueueTask(queue, kernels[1], 0, NULL, NULL); assert(err == CL_SUCCESS); clFinish(queue); }
int main(int argc, char **argv) { cl_int err; const char *krn_src; cl_program program; cl_context ctx; cl_command_queue queue; cl_device_id did; cl_kernel kernel; CHECK_CL_ERROR(poclu_get_any_device(&ctx, &did, &queue)); TEST_ASSERT(ctx); TEST_ASSERT(did); TEST_ASSERT(queue); krn_src = poclu_read_file(SRCDIR "/tests/runtime/test_clCreateKernelsInProgram.cl"); TEST_ASSERT(krn_src); program = clCreateProgramWithSource(ctx, 1, &krn_src, NULL, &err); CHECK_OPENCL_ERROR_IN("clCreateProgramWithSource"); CHECK_CL_ERROR(clBuildProgram(program, 0, NULL, NULL, NULL, NULL)); kernel = clCreateKernel(program, NULL, &err); TEST_ASSERT(err == CL_INVALID_VALUE); TEST_ASSERT(kernel == NULL); kernel = clCreateKernel(program, "nonexistent_kernel", &err); TEST_ASSERT(err == CL_INVALID_KERNEL_NAME); TEST_ASSERT(kernel == NULL); CHECK_CL_ERROR (clReleaseCommandQueue (queue)); CHECK_CL_ERROR (clReleaseProgram (program)); CHECK_CL_ERROR (clReleaseContext (ctx)); CHECK_CL_ERROR (clUnloadCompiler ()); free ((void *)krn_src); printf("OK\n"); return 0; }
int main() { int ret = 0; cl_context context; cl_device_id device; cl_command_queue command_queue; poclu_get_any_device(&context, &device, &command_queue); cl_mem faceCount_mem_obj = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(int), NULL, &ret); int faceCount = 4; ret |= clEnqueueWriteBuffer(command_queue, faceCount_mem_obj, CL_TRUE, 0, sizeof(int), &faceCount, 0, NULL, NULL); cl_int err; size_t length = strlen(kernel_src); cl_program program = clCreateProgramWithSource(context, 1, &kernel_src, &length, &err); ret |= err; clBuildProgram(program, 1, &device, "", NULL, NULL); cl_kernel kernel = clCreateKernel(program, "draw", &ret); ret |= clSetKernelArg(kernel, 0, sizeof(cl_mem),(void*)&faceCount_mem_obj); size_t global_item_size = 8; size_t workGroupSize = 4; ret |= clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global_item_size, &workGroupSize, 0, NULL, NULL); clFinish(command_queue); ret |= clReleaseKernel(kernel); return ret; }
int main(int argc, char **argv) { cl_int err; const char *krn_src; cl_program program, program2; cl_context ctx; cl_command_queue queue; cl_device_id did; cl_kernel kernel, kernel2; poclu_get_any_device(&ctx, &did, &queue); TEST_ASSERT(ctx); TEST_ASSERT(did); TEST_ASSERT(queue); krn_src = poclu_read_file(SRCDIR "/tests/runtime/test_kernel_cache_includes.cl"); TEST_ASSERT(krn_src); err = poclu_write_file(SRCDIR "/tests/runtime/test_include.h", first_include, sizeof(first_include)-1); TEST_ASSERT(err == 0); program = clCreateProgramWithSource(ctx, 1, &krn_src, NULL, &err); CHECK_OPENCL_ERROR_IN("clCreateProgramWithSource"); err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL); CHECK_OPENCL_ERROR_IN("clBuildProgram 1"); kernel = clCreateKernel(program, "testk", &err); CHECK_OPENCL_ERROR_IN("clCreateKernel 1"); size_t off[3] = {0,0,0}; size_t ws[3] = {1,1,1}; err = clEnqueueNDRangeKernel(queue, kernel, 3, off, ws, ws, 0, NULL, 0); CHECK_OPENCL_ERROR_IN("clEnqueueNDRangeKernel 1"); err = clFinish(queue); CHECK_OPENCL_ERROR_IN("clFinish 1"); /***************************************/ program2 = clCreateProgramWithSource(ctx, 1, &krn_src, NULL, &err); CHECK_OPENCL_ERROR_IN("clCreateProgramWithSource 2"); err = poclu_write_file(SRCDIR "/tests/runtime/test_include.h", second_include, sizeof(second_include)-1); TEST_ASSERT(err == 0); err = clBuildProgram(program2, 0, NULL, NULL, NULL, NULL); CHECK_OPENCL_ERROR_IN("clBuildProgram 2"); kernel2 = clCreateKernel(program2, "testk", &err); CHECK_OPENCL_ERROR_IN("clCreateKernel 2"); err = clEnqueueNDRangeKernel(queue, kernel2, 3, off, ws, ws, 0, NULL, 0); CHECK_OPENCL_ERROR_IN("clEnqueueNDRangeKernel 2"); err = clFinish(queue); CHECK_OPENCL_ERROR_IN("clFinish 2"); return 0; }
int main(int argc, char **argv) { cl_context ctx; cl_command_queue q; // root device, all devices #define NUMDEVS 6 cl_device_id rootdev, alldevs[NUMDEVS]; // pointers to the sub devices of the partitions EQUALLY and BY_COUNTS // respectively cl_device_id *eqdev = alldevs + 1, *countdev = alldevs + 4; cl_uint max_cus, max_subs, split; cl_uint i, j; cl_int err = poclu_get_any_device(&ctx, &rootdev, &q); CHECK_OPENCL_ERROR_IN("poclu_get_any_device"); TEST_ASSERT( ctx ); TEST_ASSERT( rootdev ); TEST_ASSERT( q ); alldevs[0] = rootdev; err = clGetDeviceInfo(rootdev, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(max_cus), &max_cus, NULL); CHECK_OPENCL_ERROR_IN("CL_DEVICE_MAX_COMPUTE_UNITS"); if (max_cus < 2) { printf("This test requires a cl device with at least 2 compute units" " (a dual-core or better CPU)\n"); return 1; } err = clGetDeviceInfo(rootdev, CL_DEVICE_PARTITION_MAX_SUB_DEVICES, sizeof(max_subs), &max_subs, NULL); CHECK_OPENCL_ERROR_IN("CL_DEVICE_PARTITION_MAX_SUB_DEVICES"); // test fails without possible sub-devices, e.g. with basic pocl device TEST_ASSERT(max_subs > 1); cl_device_partition_property *dev_pt; size_t dev_pt_size; err = clGetDeviceInfo(rootdev, CL_DEVICE_PARTITION_PROPERTIES, 0, NULL, &dev_pt_size); CHECK_OPENCL_ERROR_IN("CL_DEVICE_PARTITION_PROPERTIES size"); dev_pt = malloc(dev_pt_size); TEST_ASSERT(dev_pt); err = clGetDeviceInfo(rootdev, CL_DEVICE_PARTITION_PROPERTIES, dev_pt_size, dev_pt, NULL); CHECK_OPENCL_ERROR_IN("CL_DEVICE_PARTITION_PROPERTIES"); j = dev_pt_size / sizeof (*dev_pt); // number of partition types // check that partition types EQUALLY and BY_COUNTS are supported int found = 0; for (i = 0; i < j; ++i) { if (dev_pt[i] == CL_DEVICE_PARTITION_EQUALLY || dev_pt[i] == CL_DEVICE_PARTITION_BY_COUNTS) ++found; } TEST_ASSERT(found == 2); // here we will store the partition types returned by the subdevices cl_device_partition_property *ptype = NULL; size_t ptype_size; cl_uint numdevs = 0; cl_device_id parent; cl_uint sub_cus; /* CL_DEVICE_PARTITION_EQUALLY */ printf("Max CUs: %u\n", max_cus); /* if the device has 3 CUs, 3 subdevices will be created, otherwise 2. */ if (max_cus == 3) split = 3; else split = 2; const cl_device_partition_property equal_splitter[] = { CL_DEVICE_PARTITION_EQUALLY, max_cus/split, 0 }; err = clCreateSubDevices(rootdev, equal_splitter, 0, NULL, &numdevs); CHECK_OPENCL_ERROR_IN("count sub devices"); TEST_ASSERT(numdevs == split); err = clCreateSubDevices(rootdev, equal_splitter, split, eqdev, NULL); CHECK_OPENCL_ERROR_IN("partition equally"); if (split == 2) eqdev[2] = NULL; cl_uint refc; err = clGetDeviceInfo (eqdev[0], CL_DEVICE_REFERENCE_COUNT, sizeof (refc), &refc, NULL); CHECK_OPENCL_ERROR_IN ("get refcount"); TEST_ASSERT (refc == 1); /* First, check that the root device is untouched */ err = clGetDeviceInfo(rootdev, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(sub_cus), &sub_cus, NULL); CHECK_OPENCL_ERROR_IN("parenty CU"); TEST_ASSERT(sub_cus == max_cus); err = clGetDeviceInfo(rootdev, CL_DEVICE_PARENT_DEVICE, sizeof(parent), &parent, NULL); CHECK_OPENCL_ERROR_IN("root parent device"); TEST_ASSERT(parent == NULL); /* partition type may either be NULL or contain a 0 entry */ err = clGetDeviceInfo(rootdev, CL_DEVICE_PARTITION_TYPE, 0, NULL, &ptype_size); CHECK_OPENCL_ERROR_IN("root partition type"); if (ptype_size != 0) { /* abuse dev_pt which should be large enough */ TEST_ASSERT(ptype_size == sizeof(cl_device_partition_property)); TEST_ASSERT(ptype_size <= dev_pt_size); err = clGetDeviceInfo(rootdev, CL_DEVICE_PARTITION_TYPE, ptype_size, dev_pt, NULL); CHECK_OPENCL_ERROR_IN("root partition type #2"); TEST_ASSERT(dev_pt[0] == 0); } /* now test the subdevices */ for (i = 0; i < split; ++i) { err = clGetDeviceInfo(eqdev[i], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(sub_cus), &sub_cus, NULL); CHECK_OPENCL_ERROR_IN("sub CU"); TEST_ASSERT(sub_cus == max_cus/split); err = clGetDeviceInfo(eqdev[i], CL_DEVICE_PARENT_DEVICE, sizeof(parent), &parent, NULL); CHECK_OPENCL_ERROR_IN("sub parent device"); TEST_ASSERT(parent == rootdev); err = clGetDeviceInfo(eqdev[i], CL_DEVICE_PARTITION_TYPE, 0, NULL, &ptype_size); CHECK_OPENCL_ERROR_IN("sub partition type"); TEST_ASSERT(ptype_size == sizeof(equal_splitter)); ptype = malloc(ptype_size); TEST_ASSERT(ptype); err = clGetDeviceInfo(eqdev[i], CL_DEVICE_PARTITION_TYPE, ptype_size, ptype, NULL); CHECK_OPENCL_ERROR_IN("sub partition type #2"); TEST_ASSERT(memcmp(ptype, equal_splitter, ptype_size) == 0); /* free the partition type */ free(ptype) ; ptype = NULL; } /* CL_DEVICE_PARTITION_BY_COUNTS */ /* Note that the platform will only read this to the first 0, * which is actually CL_DEVICE_PARTITION_BY_COUNTS_LIST_END; * the test is structured with an additional final 0 intentionally, * to follow the Khoronos doc example */ const cl_device_partition_property count_splitter[] = { CL_DEVICE_PARTITION_BY_COUNTS, 1, max_cus - 1, CL_DEVICE_PARTITION_BY_COUNTS_LIST_END, 0 }; err = clCreateSubDevices(rootdev, count_splitter, 0, NULL, &numdevs); CHECK_OPENCL_ERROR_IN("count sub devices"); TEST_ASSERT(numdevs == 2); err = clCreateSubDevices(rootdev, count_splitter, 2, countdev, NULL); CHECK_OPENCL_ERROR_IN("partition by counts"); /* First, check that the root device is untouched */ err = clGetDeviceInfo(rootdev, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(sub_cus), &sub_cus, NULL); CHECK_OPENCL_ERROR_IN("parenty CU"); TEST_ASSERT(sub_cus == max_cus); err = clGetDeviceInfo(rootdev, CL_DEVICE_PARENT_DEVICE, sizeof(parent), &parent, NULL); CHECK_OPENCL_ERROR_IN("root parent device"); TEST_ASSERT(parent == NULL); /* partition type may either be NULL or contain a 0 entry */ err = clGetDeviceInfo(rootdev, CL_DEVICE_PARTITION_TYPE, 0, NULL, &ptype_size); CHECK_OPENCL_ERROR_IN("root partition type"); if (ptype_size != 0) { /* abuse dev_pt which should be large enough */ TEST_ASSERT(ptype_size == sizeof(cl_device_partition_property)); TEST_ASSERT(ptype_size <= dev_pt_size); err = clGetDeviceInfo(rootdev, CL_DEVICE_PARTITION_TYPE, ptype_size, dev_pt, NULL); CHECK_OPENCL_ERROR_IN("root partition type #2"); TEST_ASSERT(dev_pt[0] == 0); } // devices might be returned in different order than the counts // in the count_splitter int found_cus[2] = {0, 0}; /* now test the subdevices */ for (i = 0; i < 2; ++i) { err = clGetDeviceInfo(countdev[i], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(sub_cus), &sub_cus, NULL); CHECK_OPENCL_ERROR_IN("sub CU"); if (sub_cus == count_splitter[1]) found_cus[0] += 1; else if (sub_cus == count_splitter[2]) found_cus[1] += 1; err = clGetDeviceInfo(countdev[i], CL_DEVICE_PARENT_DEVICE, sizeof(parent), &parent, NULL); CHECK_OPENCL_ERROR_IN("sub parent device"); TEST_ASSERT(parent == rootdev); /* The partition type returned is up to the first 0, * which happens to be the CL_DEVICE_PARTITION_BY_COUNTS_LIST_END, * not the final terminating 0 in count_splitter, so it has one less * element. It should be otherwise equal */ err = clGetDeviceInfo(countdev[i], CL_DEVICE_PARTITION_TYPE, 0, NULL, &ptype_size); CHECK_OPENCL_ERROR_IN("sub partition type"); TEST_ASSERT(ptype_size == sizeof(count_splitter) - sizeof(*count_splitter)); ptype = malloc(ptype_size); TEST_ASSERT(ptype); err = clGetDeviceInfo(countdev[i], CL_DEVICE_PARTITION_TYPE, ptype_size, ptype, NULL); CHECK_OPENCL_ERROR_IN("sub partition type #2"); TEST_ASSERT(memcmp(ptype, count_splitter, ptype_size) == 0); /* free the partition type */ free(ptype) ; ptype = NULL; } /* the previous loop finds 1+1 subdevices only on >dual core systems; * on dual cores, the count_splitter is [1, 1] and the above * "(sub_cus == count_splitter[x])" results in 2+0 subdevices found */ if (max_cus > 2) TEST_ASSERT(found_cus[0] == 1 && found_cus[1] == 1); else TEST_ASSERT((found_cus[0] + found_cus[1]) == 2); /* So far, so good. Let's now try and use these devices, * by building a program for all of them and launching kernels on them. * * Note that there's a discrepancy in behavior between implementations: * some assume you can treat sub-devices as their parent device, and thus * e.g. using them through any context which includes their parent devices, * other fail miserably if you try this. * * For the time being we will test the stricter behavior, where * sub-devices should be added manually to a context. */ err = clReleaseCommandQueue(q); CHECK_OPENCL_ERROR_IN("clReleaseCommandQueue"); err = clReleaseContext(ctx); CHECK_OPENCL_ERROR_IN("clReleaseContext"); /* if we split into 2 equal parts, third pointer is NULL. Let's copy the * previous device to it */ if (split == 2) eqdev[2] = eqdev[1]; ctx = clCreateContext(NULL, NUMDEVS, alldevs, NULL, NULL, &err); CHECK_OPENCL_ERROR_IN("clCreateContext"); TEST_ASSERT( test_context(ctx, prog_src_all, 1, NUMDEVS, alldevs) == CL_SUCCESS ); ctx = clCreateContext(NULL, NUMDEVS - 1, alldevs + 1, NULL, NULL, &err); CHECK_OPENCL_ERROR_IN("clCreateContext"); TEST_ASSERT( test_context(ctx, prog_src_two, -1, NUMDEVS - 1, alldevs + 1) == CL_SUCCESS ); /* Don't release the same device twice. clReleaseDevice(NULL) should return * an error but not crash. */ if (split == 2) eqdev[2] = NULL; for (i = 0; i < NUMDEVS; i++) clReleaseDevice (alldevs[i]); CHECK_CL_ERROR (clUnloadCompiler ()); free (dev_pt); printf ("OK\n"); return 0; }
int main(int argc, char **argv) { unsigned int n = 100; double *h_a; double *h_b; double *h_c; cl_mem mem_list[3]; const void *args_mem_loc[3]; struct native_kernel_args args; cl_mem d_a; cl_mem d_b; cl_mem d_c; cl_context ctx; cl_device_id did; cl_command_queue queue; size_t bytes = n * sizeof(double); h_a = (double *) malloc(bytes); h_b = (double *) malloc(bytes); h_c = (double *) malloc(bytes); size_t i; for( i = 0; i < n; i++ ) { h_a[i] = (double)i; h_b[i] = (double)i; } cl_int err; CHECK_CL_ERROR(poclu_get_any_device(&ctx, &did, &queue)); TEST_ASSERT( ctx ); TEST_ASSERT( did ); TEST_ASSERT( queue ); d_a = clCreateBuffer(ctx, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, bytes, h_a, &err); CHECK_OPENCL_ERROR_IN("clCreateBuffer"); TEST_ASSERT(d_a); d_b = clCreateBuffer(ctx, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, bytes, h_b, &err); CHECK_OPENCL_ERROR_IN("clCreateBuffer"); TEST_ASSERT(d_b); d_c = clCreateBuffer(ctx, CL_MEM_WRITE_ONLY, bytes, NULL, &err); CHECK_OPENCL_ERROR_IN("clCreateBuffer"); TEST_ASSERT(d_c); args.size = n; args.a = 0; args.b = 0; args.c = 0; mem_list[0] = d_a; mem_list[1] = d_b; mem_list[2] = d_c; args_mem_loc[0] = &args.a; args_mem_loc[1] = &args.b; args_mem_loc[2] = &args.c; err = clEnqueueNativeKernel ( queue, native_vec_add, &args, sizeof(struct native_kernel_args), 3, mem_list, args_mem_loc, 0, NULL, NULL); CHECK_OPENCL_ERROR_IN("clEnqueueNativeKernel"); err = clEnqueueReadBuffer(queue, d_c, CL_TRUE, 0, bytes, h_c, 0, NULL, NULL ); CHECK_OPENCL_ERROR_IN("clEnqueueReadBuffer"); err = clFinish(queue); CHECK_OPENCL_ERROR_IN("clFinish"); for(i = 0; i < n; i++) if(h_c[i] != 2 * i) { printf("Fail to validate vector\n"); goto error; } CHECK_CL_ERROR (clReleaseMemObject (d_a)); CHECK_CL_ERROR (clReleaseMemObject (d_b)); CHECK_CL_ERROR (clReleaseMemObject (d_c)); CHECK_CL_ERROR (clReleaseCommandQueue (queue)); CHECK_CL_ERROR (clReleaseContext (ctx)); free(h_a); free(h_b); free(h_c); return EXIT_SUCCESS; error: return EXIT_FAILURE; }