(bind-func main
(lambda (argc:i32 argv:i8**)
(letz ((DATA_SIZE 1024)
(err:i32* (alloc)) ;; error code returned from api calls
(data:float* (alloc DATA_SIZE)) ;; original data set given to device
(results:float* (alloc DATA_SIZE)) ;; results returned from device
(correct 0) ;; number of correct results returned
(global:size_t* (alloc)) ;; global domain size for our calculation
(local:size_t* (alloc)) ;; local domain size for our calculation
(device_id:cl_device_id* (alloc)) ;; compute device id
(context:cl_context* (alloc)) ;; compute context
(commands:cl_command_queue* (alloc)) ;; compute command queue
(program:cl_program* (alloc)) ;; compute program
(kernel:cl_kernel* (alloc)) ;; compute kernel
(input:cl_mem* (alloc)) ;; device memory used for the input array
(output:cl_mem* (alloc)) ;; device memory used for the output array
(count:size_t DATA_SIZE)
(KernelSourcePtr:i8** (salloc))
(gpu #t))
;; fill data set with random values
(doloop (i DATA_SIZE)
(pset! data i (random)))
;; connect to a compute device
(pset! err 0 (clGetDeviceIDs null
(if gpu
CL_DEVICE_TYPE_GPU
CL_DEVICE_TYPE_CPU)
1
device_id
null))
(if (<> (pref err 0) CL_SUCCESS)
(println "Error: Failed to create a device group!"))
;; Create a compute context
(pset! context 0 (clCreateContext null 1 device_id null null err))
(if (null? (pref context 0))
(println "Error: Failed to create a compute context!"))
;; Create a command queue
(pset! commands 0 (clCreateCommandQueue (pref context 0) (pref device_id 0) 0 err))
(if (null? (pref commands 0))
(println "Error: Failed to create a command queue!"))
;; Create the compute program from the source buffer
(pset! KernelSourcePtr 0 KernelSource)
(pset! program 0 (clCreateProgramWithSource (pref context 0) 1 KernelSourcePtr null err))
(if (null? (pref program 0))
(println "Error: Failed to create compute program!"))
;; Build the program executable
(pset! err 0 (clBuildProgram (pref program 0) 0 null null null null))
(if (<> (pref err 0) CL_SUCCESS)
(let ((len:size_t* (salloc))
(buffer:i8* (salloc 2048)))