10 #include "COM_OpenCLKernels.cl.h"
97 printf(
"OPENCL error: %s\n", errinfo);
114 if (
context.get_has_active_opencl_devices()) {
169 if (clewInit() != CLEW_SUCCESS) {
173 if (clCreateContextFromType) {
174 cl_uint number_of_platforms = 0;
176 error = clGetPlatformIDs(0,
nullptr, &number_of_platforms);
177 if (
error == -1001) {
179 else if (
error != CL_SUCCESS) {
180 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
183 printf(
"%u number of platforms\n", number_of_platforms);
185 cl_platform_id *platforms = (cl_platform_id *)
MEM_mallocN(
186 sizeof(cl_platform_id) * number_of_platforms, __func__);
187 error = clGetPlatformIDs(number_of_platforms, platforms,
nullptr);
188 unsigned int index_platform;
189 for (index_platform = 0; index_platform < number_of_platforms; index_platform++) {
190 cl_platform_id platform = platforms[index_platform];
191 cl_uint number_of_devices = 0;
192 clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0,
nullptr, &number_of_devices);
193 if (number_of_devices <= 0) {
197 cl_device_id *cldevices = (cl_device_id *)
MEM_mallocN(
198 sizeof(cl_device_id) * number_of_devices, __func__);
199 clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, number_of_devices, cldevices,
nullptr);
203 if (
error != CL_SUCCESS) {
204 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
206 const char *cl_str[2] = {datatoc_COM_OpenCLKernels_cl,
nullptr};
215 if (
error != CL_SUCCESS) {
217 size_t ret_val_size = 0;
218 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
221 CL_PROGRAM_BUILD_LOG,
225 if (error2 != CL_SUCCESS) {
226 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
228 char *build_log = (
char *)
MEM_mallocN(
sizeof(
char) * ret_val_size + 1, __func__);
231 CL_PROGRAM_BUILD_LOG,
235 if (error2 != CL_SUCCESS) {
236 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
238 build_log[ret_val_size] =
'\0';
239 printf(
"%s", build_log);
243 unsigned int index_devices;
244 for (index_devices = 0; index_devices < number_of_devices; index_devices++) {
245 cl_device_id device = cldevices[index_devices];
247 cl_int error2 = clGetDeviceInfo(
248 device, CL_DEVICE_VENDOR_ID,
sizeof(cl_int), &vendorID,
nullptr);
249 if (error2 != CL_SUCCESS) {
250 printf(
"CLERROR[%d]: %s\n", error2, clewErrorString(error2));
382 WorkPackage *
package = static_cast<WorkPackage *>(task_data);
385 device.execute(package);
void BLI_task_pool_work_and_wait(TaskPool *pool)
TaskPool * BLI_task_pool_create(void *userdata, eTaskPriority priority)
int BLI_task_parallel_thread_id(const TaskParallelTLS *tls)
void BLI_task_pool_free(TaskPool *pool)
void BLI_task_pool_push(TaskPool *pool, TaskRunFunction run, void *taskdata, bool free_taskdata, TaskFreeFunction freedata)
void BLI_thread_queue_push(ThreadQueue *queue, void *work)
#define BLI_thread_local_create(name)
#define BLI_thread_local_set(name, value)
#define BLI_thread_local_delete(name)
void BLI_threadpool_init(struct ListBase *threadbase, void *(*do_thread)(void *), int tot)
void BLI_thread_queue_free(ThreadQueue *queue)
#define BLI_thread_local_get(name)
void BLI_threadpool_end(struct ListBase *threadbase)
void BLI_thread_queue_nowait(ThreadQueue *queue)
void BLI_thread_queue_wait_finish(ThreadQueue *queue)
void * BLI_thread_queue_pop(ThreadQueue *queue)
void BLI_threadpool_insert(struct ListBase *threadbase, void *callerdata)
ThreadQueue * BLI_thread_queue_init(void)
Read Guarded memory(de)allocation.
class representing a CPU device.
void execute(WorkPackage *work) override
execute a WorkPackage
Overall context of the compositor.
Abstract class for device implementations to be used by the Compositor. devices are queried,...
virtual void execute(struct WorkPackage *work)=0
execute a WorkPackage
const ExecutionGroupFlags get_flags() const
@ Tile
Executes an execution group tile.
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)
static void error(const char *str)
static void opencl_deinitialize()
static void opencl_initialize(const bool use_opencl)
static bool opencl_has_gpu_devices()
static void opencl_start(const CompositorContext &context)
static void threading_model_queue_deinitialize()
static void * thread_execute_gpu(void *data)
ThreadQueue * queue
all scheduled work for the cpu
constexpr ThreadingModel COM_threading_model()
static void threading_model_task_execute(TaskPool *__restrict UNUSED(pool), void *task_data)
static void threading_model_single_thread_execute(WorkPackage *package)
static void threading_model_queue_stop()
static ThreadLocal(CPUDevice *) g_thread_device
bool active
all scheduled work for the GPU.
Vector< CPUDevice > devices
list of all CPUDevices. for every hardware thread an instance of CPUDevice is created
ListBase threads
list of all thread for every CPUDevice in cpudevices a thread exists.
static void threading_model_queue_initialize(const int num_cpu_threads)
static bool opencl_schedule(WorkPackage *package)
struct blender::compositor::@179::@182 opencl
static void threading_model_queue_schedule(WorkPackage *package)
static void opencl_finish()
static void threading_model_task_stop()
static void threading_model_queue_start()
static void CL_CALLBACK cl_context_error(const char *errinfo, const void *, size_t, void *)
static struct blender::compositor::@179 g_work_scheduler
struct blender::compositor::@179::@181 task
constexpr bool COM_is_opencl_enabled()
static void threading_model_task_start()
static void * threading_model_queue_execute(void *data)
static void threading_model_task_finish()
static void threading_model_queue_finish()
static void threading_model_task_schedule(WorkPackage *package)
static void opencl_stop()
contains data about work that can be scheduled
ExecutionGroup * execution_group
execution_group with the operations-setup to be evaluated
static int get_num_cpu_threads()
static void schedule(WorkPackage *package)
schedule a chunk of a group to be calculated. An execution group schedules a chunk in the WorkSchedul...
static void deinitialize()
deinitialize the WorkScheduler free all allocated resources
static bool has_gpu_devices()
Are there OpenCL capable GPU devices initialized? the result of this method is stored in the Composit...
static void start(const CompositorContext &context)
Start the execution this methods will start the WorkScheduler. Inside this method all threads are ini...
static void finish()
wait for all work to be completed.
static void stop()
stop the execution All created thread by the start method are destroyed.
static int current_thread_id()
static void initialize(bool use_opencl, int num_cpu_threads)
initialize the WorkScheduler