Skip to content

Commit

Permalink
Added clSetPlatformDispatchDataKHR function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerilk committed Nov 21, 2023
1 parent 65062d5 commit 8ab68a6
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/CL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ set(POCL_LIB_SOURCES "clCreateContextFromType.c"
"clEnqueueMemAdviseINTEL.c"
"clEnqueueMigrateMemINTEL.c"
"clGetFunctionAddressForPlatformKHR.c"
"clSetPlatformDispatchDataKHR.c"
)

if(ANDROID)
Expand Down
3 changes: 3 additions & 0 deletions lib/CL/clGetExtensionFunctionAddressForPlatform.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ CL_API_SUFFIX__VERSION_1_2

if (strcmp (func_name, "clGetFunctionAddressForPlatformKHR") == 0)
return (void *)&POname(clGetFunctionAddressForPlatformKHR);

if (strcmp (func_name, "clSetPlatformDispatchDataKHR") == 0)
return (void *)&POname(clSetPlatformDispatchDataKHR);
#endif

#ifdef BUILD_PROXY
Expand Down
2 changes: 1 addition & 1 deletion lib/CL/clGetFunctionAddressForPlatformKHR.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* OpenCL runtime library: clGetFunctionAddressForPlatformKHR()
Copyright (c) 2017 Michal Babej / Tampere University of Technology
Copyright (c) 2023 Brice Videau / Argonne National Laboratory
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
42 changes: 42 additions & 0 deletions lib/CL/clSetPlatformDispatchDataKHR.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* OpenCL runtime library: clSetPlatformDispatchDataKHR()
Copyright (c) 2023 Brice Videau / Argonne National Laboratory
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include "pocl_cl.h"
#include "devices/devices.h"

#ifdef BUILD_ICD
POCL_EXPORT CL_API_ENTRY cl_int CL_API_CALL
POname (clSetPlatformDispatchDataKHR) (cl_platform_id platform,
void *disp_data)
{
cl_platform_id pocl_platform;

POCL_RETURN_ERROR_COND((platform == NULL), CL_INVALID_PLATFORM);
POname (clGetPlatformIDs) (1, &pocl_platform, NULL);
POCL_RETURN_ERROR_ON ((platform != pocl_platform), CL_INVALID_PLATFORM,
"Can only set dispatch data of the POCL platform\n");
platform->disp_data = disp_data;
pocl_set_devices_dispatch_data(disp_data);
return CL_SUCCESS;
}
#endif
7 changes: 7 additions & 0 deletions lib/CL/devices/devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,3 +676,10 @@ pocl_init_devices (cl_platform_id platform)
POCL_UNLOCK (pocl_init_lock);
return errcode;
}

void pocl_set_devices_dispatch_data(void *disp_data)
{
for (unsigned int i = 0; i < pocl_num_devices; i++) {
pocl_devices[i].disp_data = disp_data;
}
}
6 changes: 6 additions & 0 deletions lib/CL/devices/devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ POCL_EXPORT
int pocl_device_get_env_count(const char *dev_type);


/**
* \brief Set the disp_data field of devices if they are initialized
* \param disp_data the value to set the field to
*/
void pocl_set_devices_dispatch_data(void *disp_data);

/* the environment variable that lists the enabled devices */
#define POCL_DEVICES_ENV "POCL_DEVICES"

Expand Down
19 changes: 19 additions & 0 deletions lib/CL/pocl_cl.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,25 @@ extern uint64_t last_object_id;
#elif SIZE_MAX == UINT32_MAX
#define CL_ICD2_TAG_KHR ((size_t)UINT32_C(0x434C3331))
#endif
typedef void * CL_API_CALL
clGetFunctionAddressForPlatformKHR_t(
cl_platform_id platform,
const char* function_name);

typedef clGetFunctionAddressForPlatformKHR_t *
clGetFunctionAddressForPlatformKHR_fn;

extern clGetFunctionAddressForPlatformKHR_t clGetFunctionAddressForPlatformKHR;

typedef int CL_API_CALL
clSetPlatformDispatchDataKHR_t(
cl_platform_id platform,
void *disp_data);

typedef clSetPlatformDispatchDataKHR_t *
clSetPlatformDispatchDataKHR_fn;

extern clSetPlatformDispatchDataKHR_t clSetPlatformDispatchDataKHR;
#endif

#ifdef BUILD_ICD
Expand Down
11 changes: 1 addition & 10 deletions lib/CL/pocl_intfn.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@
extern "C" {
#endif

typedef void * CL_API_CALL
clGetFunctionAddressForPlatformKHR_t(
cl_platform_id platform,
const char* function_name);

typedef clGetFunctionAddressForPlatformKHR_t *
clGetFunctionAddressForPlatformKHR_fn;

extern clGetFunctionAddressForPlatformKHR_t clGetFunctionAddressForPlatformKHR;

POdeclsym(clBuildProgram)
POdeclsym(clLinkProgram)
POdeclsym(clCompileProgram)
Expand Down Expand Up @@ -112,6 +102,7 @@ POdeclsym(clGetSamplerInfo)
POdeclsym(clGetSupportedImageFormats)
POdeclsymICD(clIcdGetPlatformIDsKHR)
POdeclsymICD(clGetFunctionAddressForPlatformKHR)
POdeclsymICD(clSetPlatformDispatchDataKHR)
POdeclsym(clReleaseCommandQueue)
POdeclsymExport(clReleaseContext)
POdeclsymExport(clReleaseDevice)
Expand Down

0 comments on commit 8ab68a6

Please sign in to comment.