2023-05-17 17:45:47 +02:00

50 lines
1.6 KiB
C

#ifndef OPENCL_H
#define OPENCL_H
#include <stdint.h>
#include <math.h>
#include <pthread.h>
#include <stdbool.h>
#include <CL/cl.h>
#include "utils.h"
#define CHECK_CL_ERROR(ret) \
do { \
if ((ret) != CL_SUCCESS) { \
fprintf(stderr, "[%s:%d]: opencl function failed: %s\n", \
__FILE__, __LINE__, cl_get_error_string(ret)); \
} \
} while (0); \
typedef struct {
Matrixd *mat1;
Matrixd *mat2;
Matrixp *matp1;
Matrixu8 *matu8;
Matrixd *kernel_m;
cl_mem cl_buffer1;
cl_mem cl_buffer2;
cl_mem cl_result;
cl_sampler sampler;
cl_device_id device_id;
cl_context context;
cl_command_queue command_queue;
cl_program program;
cl_kernel kernel;
cl_program program1;
cl_kernel kernel1;
} cl_struct;
cl_int opencl_init(cl_struct *cl, const char *program_path);
cl_int opencl_load_kernel(cl_struct *cl, const char *path, const char *kernel_name,
cl_kernel *kernel, cl_program *program);
cl_int opencl_init_copy_host_buffers(cl_struct *cl, Matrixd *mat1, Matrixd *mat2);
cl_int opencl_init_copy_host_buffers_pixel(cl_struct *cl, Matrixp *mat1, Matrixd *mat2);
cl_int opencl_init_copy_host_buffers_mu8(cl_struct *cl, Matrixu8 *mat1, Matrixd *mat2);
cl_int opencl_execute(cl_struct* cl);
cl_int opencl_execute_image(cl_struct* cl);
cl_int opencl_read_result(cl_struct* cl);
cl_int opencl_read_result_image(cl_struct* cl);
#endif