diff options
Diffstat (limited to 'src/gallium/state_trackers/clover/api')
-rw-r--r-- | src/gallium/state_trackers/clover/api/context.cpp | 13 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/api/device.cpp | 79 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/api/kernel.cpp | 2 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/api/program.cpp | 33 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/api/queue.cpp | 8 |
5 files changed, 67 insertions, 68 deletions
diff --git a/src/gallium/state_trackers/clover/api/context.cpp b/src/gallium/state_trackers/clover/api/context.cpp index 43d5ac3b838..a03b9bb15c8 100644 --- a/src/gallium/state_trackers/clover/api/context.cpp +++ b/src/gallium/state_trackers/clover/api/context.cpp @@ -27,28 +27,23 @@ using namespace clover; PUBLIC cl_context clCreateContext(const cl_context_properties *props, cl_uint num_devs, - const cl_device_id *devs, + const cl_device_id *d_devs, void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *), void *user_data, cl_int *errcode_ret) try { + auto devs = map(addresses(), objs(d_devs, num_devs)); auto mprops = property_map(props); - if (!devs || !num_devs || - (!pfn_notify && user_data)) + if (!pfn_notify && user_data) throw error(CL_INVALID_VALUE); - if (any_of(is_zero(), range(devs, num_devs))) - throw error(CL_INVALID_DEVICE); - for (auto p : mprops) { if (p.first != CL_CONTEXT_PLATFORM) throw error(CL_INVALID_PROPERTY); } ret_error(errcode_ret, CL_SUCCESS); - return new context( - property_vector(mprops), - std::vector<cl_device_id>(devs, devs + num_devs)); + return new context(property_vector(mprops), devs); } catch(error &e) { ret_error(errcode_ret, e); diff --git a/src/gallium/state_trackers/clover/api/device.cpp b/src/gallium/state_trackers/clover/api/device.cpp index 9800779e81a..7e99f740684 100644 --- a/src/gallium/state_trackers/clover/api/device.cpp +++ b/src/gallium/state_trackers/clover/api/device.cpp @@ -28,52 +28,53 @@ using namespace clover; PUBLIC cl_int clGetDeviceIDs(cl_platform_id d_platform, cl_device_type device_type, - cl_uint num_entries, cl_device_id *devices, - cl_uint *num_devices) { + cl_uint num_entries, cl_device_id *rd_devices, + cl_uint *rnum_devices) try { auto &platform = obj(d_platform); - std::vector<cl_device_id> devs; + std::vector<cl_device_id> d_devs; - if ((!num_entries && devices) || - (!num_devices && !devices)) - return CL_INVALID_VALUE; + if ((!num_entries && rd_devices) || + (!rnum_devices && !rd_devices)) + throw error(CL_INVALID_VALUE); // Collect matching devices for (device &dev : platform) { if (((device_type & CL_DEVICE_TYPE_DEFAULT) && &dev == &platform.front()) || (device_type & dev.type())) - devs.push_back(&dev); + d_devs.push_back(desc(dev)); } - if (devs.empty()) - return CL_DEVICE_NOT_FOUND; + if (d_devs.empty()) + throw error(CL_DEVICE_NOT_FOUND); // ...and return the requested data. - if (num_devices) - *num_devices = devs.size(); - if (devices) - std::copy_n(devs.begin(), - std::min((cl_uint)devs.size(), num_entries), - devices); + if (rnum_devices) + *rnum_devices = d_devs.size(); + if (rd_devices) + copy(range(d_devs.begin(), + std::min((unsigned)d_devs.size(), num_entries)), + rd_devices); return CL_SUCCESS; + +} catch (error &e) { + return e.get(); } PUBLIC cl_int -clGetDeviceInfo(cl_device_id dev, cl_device_info param, +clGetDeviceInfo(cl_device_id d_dev, cl_device_info param, size_t size, void *r_buf, size_t *r_size) try { property_buffer buf { r_buf, size, r_size }; - - if (!dev) - return CL_INVALID_DEVICE; + auto &dev = obj(d_dev); switch (param) { case CL_DEVICE_TYPE: - buf.as_scalar<cl_device_type>() = dev->type(); + buf.as_scalar<cl_device_type>() = dev.type(); break; case CL_DEVICE_VENDOR_ID: - buf.as_scalar<cl_uint>() = dev->vendor_id(); + buf.as_scalar<cl_uint>() = dev.vendor_id(); break; case CL_DEVICE_MAX_COMPUTE_UNITS: @@ -81,15 +82,15 @@ clGetDeviceInfo(cl_device_id dev, cl_device_info param, break; case CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS: - buf.as_scalar<cl_uint>() = dev->max_block_size().size(); + buf.as_scalar<cl_uint>() = dev.max_block_size().size(); break; case CL_DEVICE_MAX_WORK_ITEM_SIZES: - buf.as_vector<size_t>() = dev->max_block_size(); + buf.as_vector<size_t>() = dev.max_block_size(); break; case CL_DEVICE_MAX_WORK_GROUP_SIZE: - buf.as_scalar<size_t>() = dev->max_threads_per_block(); + buf.as_scalar<size_t>() = dev.max_threads_per_block(); break; case CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR: @@ -129,26 +130,26 @@ clGetDeviceInfo(cl_device_id dev, cl_device_info param, break; case CL_DEVICE_MAX_READ_IMAGE_ARGS: - buf.as_scalar<cl_uint>() = dev->max_images_read(); + buf.as_scalar<cl_uint>() = dev.max_images_read(); break; case CL_DEVICE_MAX_WRITE_IMAGE_ARGS: - buf.as_scalar<cl_uint>() = dev->max_images_write(); + buf.as_scalar<cl_uint>() = dev.max_images_write(); break; case CL_DEVICE_MAX_MEM_ALLOC_SIZE: - buf.as_scalar<cl_ulong>() = dev->max_mem_alloc_size(); + buf.as_scalar<cl_ulong>() = dev.max_mem_alloc_size(); break; case CL_DEVICE_IMAGE2D_MAX_WIDTH: case CL_DEVICE_IMAGE2D_MAX_HEIGHT: - buf.as_scalar<size_t>() = 1 << dev->max_image_levels_2d(); + buf.as_scalar<size_t>() = 1 << dev.max_image_levels_2d(); break; case CL_DEVICE_IMAGE3D_MAX_WIDTH: case CL_DEVICE_IMAGE3D_MAX_HEIGHT: case CL_DEVICE_IMAGE3D_MAX_DEPTH: - buf.as_scalar<size_t>() = 1 << dev->max_image_levels_3d(); + buf.as_scalar<size_t>() = 1 << dev.max_image_levels_3d(); break; case CL_DEVICE_IMAGE_SUPPORT: @@ -156,11 +157,11 @@ clGetDeviceInfo(cl_device_id dev, cl_device_info param, break; case CL_DEVICE_MAX_PARAMETER_SIZE: - buf.as_scalar<size_t>() = dev->max_mem_input(); + buf.as_scalar<size_t>() = dev.max_mem_input(); break; case CL_DEVICE_MAX_SAMPLERS: - buf.as_scalar<cl_uint>() = dev->max_samplers(); + buf.as_scalar<cl_uint>() = dev.max_samplers(); break; case CL_DEVICE_MEM_BASE_ADDR_ALIGN: @@ -186,15 +187,15 @@ clGetDeviceInfo(cl_device_id dev, cl_device_info param, break; case CL_DEVICE_GLOBAL_MEM_SIZE: - buf.as_scalar<cl_ulong>() = dev->max_mem_global(); + buf.as_scalar<cl_ulong>() = dev.max_mem_global(); break; case CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE: - buf.as_scalar<cl_ulong>() = dev->max_const_buffer_size(); + buf.as_scalar<cl_ulong>() = dev.max_const_buffer_size(); break; case CL_DEVICE_MAX_CONSTANT_ARGS: - buf.as_scalar<cl_uint>() = dev->max_const_buffers(); + buf.as_scalar<cl_uint>() = dev.max_const_buffers(); break; case CL_DEVICE_LOCAL_MEM_TYPE: @@ -202,7 +203,7 @@ clGetDeviceInfo(cl_device_id dev, cl_device_info param, break; case CL_DEVICE_LOCAL_MEM_SIZE: - buf.as_scalar<cl_ulong>() = dev->max_mem_local(); + buf.as_scalar<cl_ulong>() = dev.max_mem_local(); break; case CL_DEVICE_ERROR_CORRECTION_SUPPORT: @@ -214,7 +215,7 @@ clGetDeviceInfo(cl_device_id dev, cl_device_info param, break; case CL_DEVICE_ENDIAN_LITTLE: - buf.as_scalar<cl_bool>() = (dev->endianness() == PIPE_ENDIAN_LITTLE); + buf.as_scalar<cl_bool>() = (dev.endianness() == PIPE_ENDIAN_LITTLE); break; case CL_DEVICE_AVAILABLE: @@ -231,11 +232,11 @@ clGetDeviceInfo(cl_device_id dev, cl_device_info param, break; case CL_DEVICE_NAME: - buf.as_string() = dev->device_name(); + buf.as_string() = dev.device_name(); break; case CL_DEVICE_VENDOR: - buf.as_string() = dev->vendor_name(); + buf.as_string() = dev.vendor_name(); break; case CL_DRIVER_VERSION: @@ -255,7 +256,7 @@ clGetDeviceInfo(cl_device_id dev, cl_device_info param, break; case CL_DEVICE_PLATFORM: - buf.as_scalar<cl_platform_id>() = desc(dev->platform); + buf.as_scalar<cl_platform_id>() = desc(dev.platform); break; case CL_DEVICE_HOST_UNIFIED_MEMORY: diff --git a/src/gallium/state_trackers/clover/api/kernel.cpp b/src/gallium/state_trackers/clover/api/kernel.cpp index 0ebe479de8b..a1152652a59 100644 --- a/src/gallium/state_trackers/clover/api/kernel.cpp +++ b/src/gallium/state_trackers/clover/api/kernel.cpp @@ -165,7 +165,7 @@ clGetKernelWorkGroupInfo(cl_kernel kern, cl_device_id dev, return CL_INVALID_KERNEL; if ((!dev && kern->prog.binaries().size() != 1) || - (dev && !kern->prog.binaries().count(dev))) + (dev && !kern->prog.binaries().count(pobj(dev)))) return CL_INVALID_DEVICE; switch (param) { diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp index 972f1566ccc..5d6dd040ad5 100644 --- a/src/gallium/state_trackers/clover/api/program.cpp +++ b/src/gallium/state_trackers/clover/api/program.cpp @@ -54,19 +54,21 @@ clCreateProgramWithSource(cl_context ctx, cl_uint count, } PUBLIC cl_program -clCreateProgramWithBinary(cl_context ctx, cl_uint count, - const cl_device_id *devs, const size_t *lengths, +clCreateProgramWithBinary(cl_context ctx, cl_uint n, + const cl_device_id *d_devs, const size_t *lengths, const unsigned char **binaries, cl_int *status_ret, cl_int *errcode_ret) try { + auto devs = objs(d_devs, n); + if (!ctx) throw error(CL_INVALID_CONTEXT); - if (!count || !devs || !lengths || !binaries) + if (!lengths || !binaries) throw error(CL_INVALID_VALUE); - if (any_of([&](const cl_device_id dev) { - return !ctx->has_device(dev); - }, range(devs, count))) + if (any_of([&](device &dev) { + return !ctx->has_device(&dev); + }, devs)) throw error(CL_INVALID_DEVICE); // Deserialize the provided binaries, @@ -85,8 +87,8 @@ clCreateProgramWithBinary(cl_context ctx, cl_uint count, return { CL_INVALID_BINARY, {} }; } }, - range(binaries, count), - range(lengths, count)); + range(binaries, n), + range(lengths, n)); // update the status array, if (status_ret) @@ -100,8 +102,7 @@ clCreateProgramWithBinary(cl_context ctx, cl_uint count, // initialize a program object with them. ret_error(errcode_ret, CL_SUCCESS); - return new program(*ctx, { devs, devs + count }, - map(values(), modules)); + return new program(*ctx, map(addresses(), devs), map(values(), modules)); } catch (error &e) { ret_error(errcode_ret, e); @@ -144,11 +145,11 @@ clBuildProgram(cl_program prog, cl_uint count, const cl_device_id *devs, if (devs) { if (any_of([&](const cl_device_id dev) { - return !prog->ctx.has_device(dev); + return !prog->ctx.has_device(pobj(dev)); }, range(devs, count))) throw error(CL_INVALID_DEVICE); - prog->build({ devs, devs + count }, opts); + prog->build(map(addresses(), objs(devs, count)), opts); } else { prog->build(prog->ctx.devs, opts); } @@ -234,20 +235,20 @@ clGetProgramBuildInfo(cl_program prog, cl_device_id dev, if (!prog) return CL_INVALID_PROGRAM; - if (!prog->ctx.has_device(dev)) + if (!prog->ctx.has_device(pobj(dev))) return CL_INVALID_DEVICE; switch (param) { case CL_PROGRAM_BUILD_STATUS: - buf.as_scalar<cl_build_status>() = prog->build_status(dev); + buf.as_scalar<cl_build_status>() = prog->build_status(pobj(dev)); break; case CL_PROGRAM_BUILD_OPTIONS: - buf.as_string() = prog->build_opts(dev); + buf.as_string() = prog->build_opts(pobj(dev)); break; case CL_PROGRAM_BUILD_LOG: - buf.as_string() = prog->build_log(dev); + buf.as_string() = prog->build_log(pobj(dev)); break; default: diff --git a/src/gallium/state_trackers/clover/api/queue.cpp b/src/gallium/state_trackers/clover/api/queue.cpp index b2927ecabef..8e500fa03ed 100644 --- a/src/gallium/state_trackers/clover/api/queue.cpp +++ b/src/gallium/state_trackers/clover/api/queue.cpp @@ -26,13 +26,15 @@ using namespace clover; PUBLIC cl_command_queue -clCreateCommandQueue(cl_context ctx, cl_device_id dev, +clCreateCommandQueue(cl_context ctx, cl_device_id d_dev, cl_command_queue_properties props, cl_int *errcode_ret) try { + auto &dev = obj(d_dev); + if (!ctx) throw error(CL_INVALID_CONTEXT); - if (!ctx->has_device(dev)) + if (!ctx->has_device(&dev)) throw error(CL_INVALID_DEVICE); if (props & ~(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | @@ -40,7 +42,7 @@ clCreateCommandQueue(cl_context ctx, cl_device_id dev, throw error(CL_INVALID_VALUE); ret_error(errcode_ret, CL_SUCCESS); - return new command_queue(*ctx, *dev, props); + return new command_queue(*ctx, dev, props); } catch (error &e) { ret_error(errcode_ret, e); |