// Build the program executable 96. clBuildProgram(program, 0, NULL, NULL, NULL, NULL); 97. 98. // Create the compute kernel in the program we wish to run 99. kernel = clCreateKernel(program, "vecAdd", &err); 100. 101. // Create the input and output arrays in device memory for our calculation 102. d_a = clCreateBuffer(context, CL_MEM_READ_ONLY, bytes, NULL, NULL); 103. d_b = clCreateBuffer(context, CL_MEM_READ_ONLY, bytes, NULL, NULL); 104. d_c = clCreateBuffer(context, CL_MEM_WRITE_ONLY, bytes, NULL, NULL); 105. 106. // Write our data set into the input array in device memory 107. err = clEnqueueWriteBuffer(queue, d_a, CL_TRUE, 0, 108. bytes, h_a, 0, NULL, NULL); 109. err |= clEnqueueWriteBuffer(queue, d_b, CL_TRUE, 0, 110. bytes, h_b, 0, NULL, NULL); 111. 112. // Set the arguments to our compute kernel 113. err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &d_a); 114. err |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &d_b); 115. err |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &d_c); 116. err |= clSetKernelArg(kernel, 3, sizeof(unsigned int), &n); 117. 118. // Execute the kernel over the entire range of the data set 119. err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &globalSize, &localSize, 0, NULL, NULL); 120. 121. // Wait for the command queue to get serviced before reading back results 122. clFinish(queue);