24 #include "COM_OpenCLKernels.cl.h"
112 printf(
"OPENCL error: %s\n", errinfo);
129 if (
context.getHasActiveOpenCLDevices()) {
183 if (clewInit() != CLEW_SUCCESS) {
187 if (clCreateContextFromType) {
188 cl_uint numberOfPlatforms = 0;
190 error = clGetPlatformIDs(0,
nullptr, &numberOfPlatforms);
191 if (
error == -1001) {
193 else if (
error != CL_SUCCESS) {
194 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
197 printf(
"%u number of platforms\n", numberOfPlatforms);
199 cl_platform_id *platforms = (cl_platform_id *)
MEM_mallocN(
200 sizeof(cl_platform_id) * numberOfPlatforms, __func__);
201 error = clGetPlatformIDs(numberOfPlatforms, platforms,
nullptr);
202 unsigned int indexPlatform;
203 for (indexPlatform = 0; indexPlatform < numberOfPlatforms; indexPlatform++) {
204 cl_platform_id platform = platforms[indexPlatform];
205 cl_uint numberOfDevices = 0;
206 clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0,
nullptr, &numberOfDevices);
207 if (numberOfDevices <= 0) {
211 cl_device_id *cldevices = (cl_device_id *)
MEM_mallocN(
212 sizeof(cl_device_id) * numberOfDevices, __func__);
213 clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numberOfDevices, cldevices,
nullptr);
217 if (
error != CL_SUCCESS) {
218 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
220 const char *cl_str[2] = {datatoc_COM_OpenCLKernels_cl,
nullptr};
229 if (
error != CL_SUCCESS) {
231 size_t ret_val_size = 0;
232 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
235 CL_PROGRAM_BUILD_LOG,
239 if (error2 != CL_SUCCESS) {
240 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
242 char *build_log = (
char *)
MEM_mallocN(
sizeof(
char) * ret_val_size + 1, __func__);
245 CL_PROGRAM_BUILD_LOG,
249 if (error2 != CL_SUCCESS) {
250 printf(
"CLERROR[%d]: %s\n",
error, clewErrorString(
error));
252 build_log[ret_val_size] =
'\0';
253 printf(
"%s", build_log);
257 unsigned int indexDevices;
258 for (indexDevices = 0; indexDevices < numberOfDevices; indexDevices++) {
259 cl_device_id device = cldevices[indexDevices];
261 cl_int error2 = clGetDeviceInfo(
262 device, CL_DEVICE_VENDOR_ID,
sizeof(cl_int), &vendorID,
nullptr);
263 if (error2 != CL_SUCCESS) {
264 printf(
"CLERROR[%d]: %s\n", error2, clewErrorString(error2));
370 for (
int index = 0; index < num_cpu_threads; index++) {
396 WorkPackage *
package = static_cast<WorkPackage *>(task_data);
399 device.execute(package);
void BLI_task_pool_work_and_wait(TaskPool *pool)
int BLI_task_parallel_thread_id(const TaskParallelTLS *tls)
TaskPool * BLI_task_pool_create(void *userdata, TaskPriority priority)
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.
Platform independent time functions.
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
device representing an GPU OpenCL device. an instance of this class represents a single cl_device
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 threading_model_queue_deinitialize()
static void * thread_execute_gpu(void *data)
ThreadQueue * queue
all scheduled work for the cpu
static void CL_CALLBACK clContextError(const char *errinfo, const void *, size_t, void *)
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 void opencl_start(CompositorContext &context)
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)
static void threading_model_queue_schedule(WorkPackage *package)
static void opencl_finish()
static void threading_model_task_stop()
static struct blender::compositor::@172 g_work_scheduler
static void threading_model_queue_start()
struct blender::compositor::@172::@174 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()
struct blender::compositor::@172::@175 opencl
contains data about work that can be scheduled
ExecutionGroup * execution_group
executionGroup with the operations-setup to be evaluated
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 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 start(CompositorContext &context)
Start the execution this methods will start the WorkScheduler. Inside this method all threads are ini...
static void initialize(bool use_opencl, int num_cpu_threads)
initialize the WorkScheduler