Skip to content

Commit

Permalink
[SYCL][CUDA] Fix device query for image support (#1299)
Browse files Browse the repository at this point in the history
Init plugin function table to 0.
As the PI plugin function table can grow without the CUDA plugin being
adapted, set the whole function pointer table to 0 to trigger crashes
on calling functions that are not set.

Signed-off-by: Bjoern Knafla <bjoern@codeplay.com>
  • Loading branch information
bjoernknafla authored Mar 14, 2020
1 parent 1f3bd3d commit 0d56408
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/pi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ std::string platformInfoToString(pi_platform_info info);
template <class To, class From> To cast(From value);

// Holds the PluginInformation for the plugin that is bound.
// Currently a global varaible is used to store OpenCL plugin information to be
// Currently a global variable is used to store OpenCL plugin information to be
// used with SYCL Interoperability Constructors.
extern std::shared_ptr<plugin> GlobalPlugin;

Expand Down
10 changes: 9 additions & 1 deletion sycl/plugins/cuda/pi_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,8 @@ pi_result cuda_piDeviceGetInfo(pi_device device, pi_device_info param_name,
pi_uint64{max_alloc});
}
case PI_DEVICE_INFO_IMAGE_SUPPORT: {
return getInfo(param_value_size, param_value, param_value_size_ret, false);
return getInfo(param_value_size, param_value, param_value_size_ret,
PI_FALSE);
}
case PI_DEVICE_INFO_MAX_READ_IMAGE_ARGS: {
return getInfo(param_value_size, param_value, param_value_size_ret, 0);
Expand Down Expand Up @@ -3021,6 +3022,11 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
// PI interface supports higher version or the same version.
strncpy(PluginInit->PluginVersion, SupportedVersion, 4);

// Set whole function table to zero to make it easier to detect if
// functions are not set up below.
std::memset(&(PluginInit->PiFunctionTable), 0,
sizeof(PluginInit->PiFunctionTable));

// Forward calls to OpenCL RT.
#define _PI_CL(pi_api, cuda_api) \
(PluginInit->PiFunctionTable).pi_api = (decltype(&::pi_api))(&cuda_api);
Expand Down Expand Up @@ -3075,6 +3081,7 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
_PI_CL(piKernelRetain, cuda_piKernelRetain)
_PI_CL(piKernelRelease, cuda_piKernelRelease)
_PI_CL(piKernelSetExecInfo, cuda_piKernelSetExecInfo)

// Event
_PI_CL(piEventCreate, cuda_piEventCreate)
_PI_CL(piEventGetInfo, cuda_piEventGetInfo)
Expand Down Expand Up @@ -3106,6 +3113,7 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
_PI_CL(piEnqueueMemImageFill, cuda_piEnqueueMemImageFill)
_PI_CL(piEnqueueMemBufferMap, cuda_piEnqueueMemBufferMap)
_PI_CL(piEnqueueMemUnmap, cuda_piEnqueueMemUnmap)

_PI_CL(piextKernelSetArgMemObj, cuda_piextKernelSetArgMemObj)

#undef _PI_CL
Expand Down

0 comments on commit 0d56408

Please sign in to comment.