diff options
author | Francisco Jerez <[email protected]> | 2013-04-06 14:35:00 +0200 |
---|---|---|
committer | Francisco Jerez <[email protected]> | 2013-04-13 14:20:16 +0200 |
commit | 1a8ad6c2e3beb00d07ef109b984658e08c5729da (patch) | |
tree | 9daa3310cadfd311ebb92109c131f920419293a8 /src/gallium/state_trackers/clover/api | |
parent | 6ace4520559094b755ff1eb038ac68f38faa83c6 (diff) |
clover: Define platform class and merge with device_registry.
Null platform IDs are OK according to the spec, but some applications have
been reported to get paranoid and assume that our NULL platform is unusable.
As it doesn't hurt to have device enumeration separate from the rest of the
device code (quite the opposite, it makes the code cleaner), make the API use
an actual platform object that keeps track of the available devices instead of
the former NULL pointer.
Reported-and-reviewed-by: Tom Stellard <[email protected]>
Signed-off-by: Francisco Jerez <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/clover/api')
-rw-r--r-- | src/gallium/state_trackers/clover/api/context.cpp | 23 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/api/device.cpp | 16 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/api/platform.cpp | 7 |
3 files changed, 27 insertions, 19 deletions
diff --git a/src/gallium/state_trackers/clover/api/context.cpp b/src/gallium/state_trackers/clover/api/context.cpp index 80afb6bf4ec..99b95666401 100644 --- a/src/gallium/state_trackers/clover/api/context.cpp +++ b/src/gallium/state_trackers/clover/api/context.cpp @@ -41,8 +41,7 @@ clCreateContext(const cl_context_properties *props, cl_uint num_devs, throw error(CL_INVALID_DEVICE); for (auto p : mprops) { - if (!(p.first == CL_CONTEXT_PLATFORM && - (cl_platform_id)p.second == NULL)) + if (p.first != CL_CONTEXT_PLATFORM) throw error(CL_INVALID_PROPERTY); } @@ -61,17 +60,25 @@ clCreateContextFromType(const cl_context_properties *props, cl_device_type type, void (CL_CALLBACK *pfn_notify)( const char *, const void *, size_t, void *), - void *user_data, cl_int *errcode_ret) { + void *user_data, cl_int *errcode_ret) try { + cl_platform_id platform; + cl_uint num_platforms; cl_device_id dev; cl_int ret; - ret = clGetDeviceIDs(0, type, 1, &dev, 0); - if (ret) { - ret_error(errcode_ret, ret); - return NULL; - } + ret = clGetPlatformIDs(1, &platform, &num_platforms); + if (ret || !num_platforms) + throw error(CL_INVALID_PLATFORM); + + ret = clGetDeviceIDs(platform, type, 1, &dev, 0); + if (ret) + throw error(CL_DEVICE_NOT_FOUND); return clCreateContext(props, 1, &dev, pfn_notify, user_data, errcode_ret); + +} catch(error &e) { + ret_error(errcode_ret, e); + return NULL; } PUBLIC cl_int diff --git a/src/gallium/state_trackers/clover/api/device.cpp b/src/gallium/state_trackers/clover/api/device.cpp index cf68d0fc18c..cd8095d3c7e 100644 --- a/src/gallium/state_trackers/clover/api/device.cpp +++ b/src/gallium/state_trackers/clover/api/device.cpp @@ -21,29 +21,25 @@ // #include "api/util.hpp" +#include "core/platform.hpp" #include "core/device.hpp" using namespace clover; -static device_registry registry; - PUBLIC cl_int clGetDeviceIDs(cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id *devices, cl_uint *num_devices) { std::vector<cl_device_id> devs; - if (platform != NULL) - return CL_INVALID_PLATFORM; - if ((!num_entries && devices) || (!num_devices && !devices)) return CL_INVALID_VALUE; // Collect matching devices - for (device &dev : registry) { + for (device &dev : *platform) { if (((device_type & CL_DEVICE_TYPE_DEFAULT) && - &dev == ®istry.front()) || + &dev == &platform->front()) || (device_type & dev.type())) devs.push_back(&dev); } @@ -223,13 +219,15 @@ clGetDeviceInfo(cl_device_id dev, cl_device_info param, return string_property(buf, size, size_ret, "FULL_PROFILE"); case CL_DEVICE_VERSION: - return string_property(buf, size, size_ret, "OpenCL 1.1 MESA " PACKAGE_VERSION); + return string_property(buf, size, size_ret, + "OpenCL 1.1 MESA " PACKAGE_VERSION); case CL_DEVICE_EXTENSIONS: return string_property(buf, size, size_ret, ""); case CL_DEVICE_PLATFORM: - return scalar_property<cl_platform_id>(buf, size, size_ret, NULL); + return scalar_property<cl_platform_id>(buf, size, size_ret, + &dev->platform); case CL_DEVICE_HOST_UNIFIED_MEMORY: return scalar_property<cl_bool>(buf, size, size_ret, CL_TRUE); diff --git a/src/gallium/state_trackers/clover/api/platform.cpp b/src/gallium/state_trackers/clover/api/platform.cpp index f99b6949356..90111c7e2dc 100644 --- a/src/gallium/state_trackers/clover/api/platform.cpp +++ b/src/gallium/state_trackers/clover/api/platform.cpp @@ -21,9 +21,12 @@ // #include "api/util.hpp" +#include "core/platform.hpp" using namespace clover; +static platform __platform; + PUBLIC cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms) { @@ -34,7 +37,7 @@ clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, if (num_platforms) *num_platforms = 1; if (platforms) - *platforms = NULL; + *platforms = &__platform; return CL_SUCCESS; } @@ -42,7 +45,7 @@ clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, PUBLIC cl_int clGetPlatformInfo(cl_platform_id platform, cl_platform_info param_name, size_t size, void *buf, size_t *size_ret) { - if (platform != NULL) + if (platform != &__platform) return CL_INVALID_PLATFORM; switch (param_name) { |