Loading...
Searching...
No Matches
cl.h
Go to the documentation of this file.
1#pragma once
2
13
14#define CL_TARGET_OPENCL_VERSION 220
15
16#include <CL/cl.h>
17#include <pthread.h>
18
21#define NUT_CL_FLAG_DIE 0x1
24#define NUT_CL_FLAG_VERBOSE 0x2
28#define NUT_CL_FLAG_MT_SAFE 0x4
29
30typedef struct{
31 cl_kernel kernel;
32 size_t preferred_work_group_size_multiple;
33 size_t work_group_size;
34 size_t work_item_sizes[];
36
40typedef struct{
41 int flags;
42 cl_int err;
43 cl_uint num_platforms;
44 cl_platform_id *platform_ids;
45 cl_uint num_devices;
46 cl_device_id *device_ids;
47 cl_uint max_compute_units;
48 cl_uint max_work_item_dimensions;
49 size_t max_work_group_size;
50 size_t *max_work_item_sizes;
51 cl_context context;
52 cl_command_queue queue;
53 size_t programs_len, programs_cap;
54 cl_program *programs;
55 size_t kernels_len, kernels_cap;
56 nut_ClKernel *kernels;
57 pthread_mutex_t log_lock;
58} nut_ClMgr;
59
72bool nut_cl_check_err(nut_ClMgr *mgr, const char *title, const char *subtitle);
73
83bool nut_cl_setup(nut_ClMgr *mgr, int flags);
84
93
100const char *nut_cl_read_source(nut_ClMgr *mgr, const char *filename);
101
116bool nut_cl_make_program_from_source(nut_ClMgr *mgr, const char *source);
117
128bool nut_cl_create_kernel(nut_ClMgr *mgr, size_t program_idx, const char *name);
129
136bool nut_cl_create_all_kernels(nut_ClMgr *mgr, size_t program_idx);
137
bool nut_cl_create_kernel(nut_ClMgr *mgr, size_t program_idx, const char *name)
Create one kernel with a given name program_idx should be the index of the program in mgr.
bool nut_cl_make_program_from_source(nut_ClMgr *mgr, const char *source)
Compile OpenCL source read into an OpenCL program The source should come from nut_cl_read_source.
const char * nut_cl_read_source(nut_ClMgr *mgr, const char *filename)
Read an OpenCL source file (.cl) into a string The filename can be any relative path,...
void nut_cl_close(nut_ClMgr *mgr)
Shut down OpenCL and clean up all resources associated with mgr This cleans up all programs,...
bool nut_cl_check_err(nut_ClMgr *mgr, const char *title, const char *subtitle)
Check and report/resolve OpenCL errors after manually calling OpenCL functions Will print errors and/...
bool nut_cl_setup(nut_ClMgr *mgr, int flags)
Initialize OpenCL and store the relevant state in mgr The first available platform and device will be...
bool nut_cl_create_all_kernels(nut_ClMgr *mgr, size_t program_idx)
Create all kernels within a given program Automatically extracts kernel names from the program and ge...
Manages "global" OpenCL state including programs, kernels, the context, and the command queue.
Definition cl.h:40