diff --git a/CHANGELOG.md b/CHANGELOG.md index bfa3f68fca..a815f2ffdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. +## [Unreleased] +### Removed +- The Legacy OpenCL interface. + ## [0.3.6] - 2020-10-06 ### Added - Changelog was added for dpctl. diff --git a/README.md b/README.md index 57b1a322f3..fd54be2f92 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,7 @@ What? ==== -A lightweight Python package exposing a subset of OpenCL and SYCL -functionalities. +A lightweight Python package exposing a subset of SYCL functionalities. Requirements ============ diff --git a/backends/CMakeLists.txt b/backends/CMakeLists.txt index 2c4fda3157..4dce2cdd18 100644 --- a/backends/CMakeLists.txt +++ b/backends/CMakeLists.txt @@ -86,13 +86,6 @@ else() message(FATAL_ERROR "Unsupported system.") endif() - -set(OpenCL_INCLUDE_DIR "${DPCPP_ROOT}/include/sycl") -set(OpenCL_LIBRARY "${DPCPP_ROOT}/lib/libOpenCL.so") - -message(STATUS "OpenCL_INCLUDE_DIR: ${OpenCL_INCLUDE_DIR}") -message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}") - add_library( DPPLSyclInterface SHARED @@ -108,13 +101,6 @@ add_library( source/dppl_utils.cpp ) -# Install DPPLOpenCLInterface -add_library( - DPPLOpenCLInterface - SHARED - source/dppl_opencl_interface.c -) - # Install DPPLSyclInterface target_include_directories( DPPLSyclInterface @@ -124,18 +110,6 @@ target_include_directories( ${NUMPY_INCLUDE_DIR} ) -target_include_directories( - DPPLOpenCLInterface - PRIVATE - ${CMAKE_SOURCE_DIR}/include/ -) - -target_include_directories( - DPPLOpenCLInterface - PUBLIC - ${OpenCL_INCLUDE_DIR} -) - if(WIN32) message( STATUS @@ -152,10 +126,6 @@ if(WIN32) PRIVATE ${DPCPP_ROOT}/lib/sycl.lib PRIVATE ${DPCPP_ROOT}/lib/OpenCL.lib ) - target_link_libraries( - DPPLOpenCLInterface - PRIVATE ${DPCPP_ROOT}/lib/OpenCL.lib - ) endif() install( @@ -165,14 +135,6 @@ install( "${CMAKE_INSTALL_PREFIX}/lib/" ) -install( - TARGETS - DPPLOpenCLInterface - LIBRARY - DESTINATION - "${CMAKE_INSTALL_PREFIX}/lib/" -) - # Install all headers file(GLOB HEADERS "${CMAKE_SOURCE_DIR}/include/*.h*") foreach(HEADER ${HEADERS}) diff --git a/backends/include/dppl_opencl_interface.h b/backends/include/dppl_opencl_interface.h deleted file mode 100644 index a34845bbe5..0000000000 --- a/backends/include/dppl_opencl_interface.h +++ /dev/null @@ -1,312 +0,0 @@ -//===------------ dppl_opencl_interface.h - dpctl-C_API -------*- C -*-----===// -// -// Data Parallel Control Library (dpCtl) -// -// Copyright 2020 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//===----------------------------------------------------------------------===// -/// -/// \file -/// This file contains the declaration of a C API to expose a lightweight OpenCL -/// interface for the Python dpctl package. -/// -//===----------------------------------------------------------------------===// - -#pragma once - -#include -#include - - -#ifdef _WIN32 -# ifdef DPPLOpenCLInterface_EXPORTS -# define DPPL_API __declspec(dllexport) -# else -# define DPPL_API __declspec(dllimport) -# endif -#else -# define DPPL_API -#endif - - -enum DP_GLUE_ERROR_CODES -{ - DP_GLUE_SUCCESS = 0, - DP_GLUE_FAILURE = -1 -}; - - -/*! - * - */ -struct dp_env -{ - unsigned id_; - // TODO : Add members to store more device related information such as name - void *context; - void *device; - void *queue; - unsigned int max_work_item_dims; - size_t max_work_group_size; - int support_int64_atomics; - int support_float64_atomics; - int (*dump_fn) (void *); -}; - -typedef struct dp_env* env_t; - - -struct dp_buffer -{ - unsigned id_; - // This may, for example, be a cl_mem pointer - void *buffer_ptr; - // Stores the size of the buffer_ptr (e.g sizeof(cl_mem)) - size_t sizeof_buffer_ptr; -}; - -typedef struct dp_buffer* buffer_t; - - -struct dp_kernel -{ - unsigned id_; - void *kernel; - int (*dump_fn) (void *); -}; - -typedef struct dp_kernel* kernel_t; - - -struct dp_program -{ - unsigned id_; - void *program; -}; - -typedef struct dp_program* program_t; - - -struct dp_kernel_arg -{ - unsigned id_; - const void *arg_value; - size_t arg_size; -}; - -typedef struct dp_kernel_arg* kernel_arg_t; - - -/*! @struct dp_runtime_t - * @brief Stores an array of the available OpenCL or Level-0 platform/drivers. - * - * @var dp_runtime_t::num_platforms - * Depicts the number of platforms/drivers available on this system - * - * @var dp_runtime_t::platforms_ids - * An array of OpenCL platforms. - * - */ -struct dp_runtime -{ - unsigned id_; - unsigned num_platforms; - void *platform_ids; - bool has_cpu; - bool has_gpu; - env_t first_cpu_env; - env_t first_gpu_env; - env_t curr_env; - int (*dump_fn) (void *); -}; - -typedef struct dp_runtime* runtime_t; - -DPPL_API -int set_curr_env (runtime_t rt, env_t env); - -/*! - * @brief Initializes a new dp_runtime_t object - * - * @param[in/out] rt - An uninitialized runtime_t pointer that is initialized - * by the function. - * - * @return An error code indicating if the runtime_t object was successfully - * initialized. - */ -DPPL_API -int create_dp_runtime (runtime_t *rt); - - -/*! - * @brief Free the runtime and all its resources. - * - * @param[in] rt - Pointer to the numba_one_api_runtime_t object to be freed - * - * @return An error code indicating if resource freeing was successful. - */ -DPPL_API -int destroy_dp_runtime (runtime_t *rt); - - -/*! - * - */ -DPPL_API -int create_dp_rw_mem_buffer (env_t env_t_ptr, size_t buffsize, buffer_t *buff); - - -DPPL_API -int destroy_dp_rw_mem_buffer (buffer_t *buff); - - -/*! - * - */ -DPPL_API -int write_dp_mem_buffer_to_device (env_t env_t_ptr, - buffer_t buff, - bool blocking_copy, - size_t offset, - size_t buffersize, - const void *data_ptr); - - -/*! - * - */ -DPPL_API -int read_dp_mem_buffer_from_device (env_t env_t_ptr, - buffer_t buff, - bool blocking_copy, - size_t offset, - size_t buffersize, - void *data_ptr); - - -/*! - * - */ -DPPL_API -int create_dp_program_from_spirv (env_t env_t_ptr, - const void *il, - size_t length, - program_t *program_t_ptr); - - -/*! - * - */ -DPPL_API -int create_dp_program_from_source (env_t env_t_ptr, - unsigned int count, - const char **strings, - const size_t *lengths, - program_t *program_t_ptr); - -/*! - * - */ -DPPL_API -int destroy_dp_program (program_t *program_t_ptr); - - -DPPL_API -int build_dp_program (env_t env_t_ptr, program_t program_t_ptr); - -/*! - * - */ -DPPL_API -int create_dp_kernel (env_t env_t_ptr, - program_t program_ptr, - const char *kernel_name, - kernel_t *kernel_ptr); - - -DPPL_API -int destroy_dp_kernel (kernel_t *kernel_ptr); - - -/*! - * - */ -DPPL_API -int create_dp_kernel_arg (const void *arg_value, - size_t arg_size, - kernel_arg_t *kernel_arg_t_ptr); - - -/*! - * - */ -DPPL_API -int create_dp_kernel_arg_from_buffer (buffer_t *buffer_t_ptr, - kernel_arg_t *kernel_arg_t_ptr); - - -/*! - * - */ -DPPL_API -int destroy_dp_kernel_arg (kernel_arg_t *kernel_arg_t_ptr); - - -/*! - * - */ -DPPL_API -int set_args_and_enqueue_dp_kernel (env_t env_t_ptr, - kernel_t kernel_t_ptr, - size_t nargs, - const kernel_arg_t *args, - unsigned int work_dim, - const size_t *global_work_offset, - const size_t *global_work_size, - const size_t *local_work_size); - - -/*! - * - */ -DPPL_API -int set_args_and_enqueue_dp_kernel_auto_blocking (env_t env_t_ptr, - kernel_t kernel_t_ptr, - size_t nargs, - const kernel_arg_t *args, - unsigned int num_dims, - size_t *dim_starts, - size_t *dim_stops); - - -/*! - * - */ -DPPL_API -int retain_dp_context (env_t env_t_ptr); - - -/*! - * - */ -DPPL_API -int release_dp_context (env_t env_t_ptr); - - -//---- TODO: - -// 1. Add release/retain methods for buffers - -//--------- diff --git a/backends/include/error_check_macros.h b/backends/include/error_check_macros.h deleted file mode 100644 index c532f89127..0000000000 --- a/backends/include/error_check_macros.h +++ /dev/null @@ -1,111 +0,0 @@ -//===----------- error_check_macros.h - dpctl-C_API-------*- C ------*-----===// -// -// Data Parallel Control Library (dpCtl) -// -// Copyright 2020 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//===----------------------------------------------------------------------===// -/// -/// \file -/// This file contains a set of macros to check for different OpenCL error -/// codes. -/// -//===----------------------------------------------------------------------===// - -#pragma once - -#include - -// TODO : Add branches to check for OpenCL error codes and print relevant error -// messages. Then there would be no need to pass in the message string - -// FIXME : The error check macro needs to be improved. Currently, we encounter -// an error and goto the error label. Directly going to the error label can lead -// to us not releasing resources prior to returning from the function. To work -// around this situation, add a stack to store all the objects that should be -// released prior to returning. The stack gets populated as a function executes -// and on encountering an error, all objects on the stack get properly released -// prior to returning. (Look at enqueue_dp_kernel_from_source for a -// ghastly example where we really need proper resource management.) - -// FIXME : memory allocated in a function should be released in the error -// section - -#define CHECK_OPEN_CL_ERROR(x, M) do { \ - int retval = (x); \ - switch(retval) { \ - case 0: \ - break; \ - case -36: \ - fprintf(stderr, "Open CL Runtime Error: %d (%s) on Line %d in %s\n", \ - retval, "[CL_INVALID_COMMAND_QUEUE]command_queue is not a " \ - "valid command-queue.", \ - __LINE__, __FILE__); \ - goto error; \ - case -38: \ - fprintf(stderr, "Open CL Runtime Error: %d (%s) on Line %d in %s\n" \ - "%s\n", \ - retval, "[CL_INVALID_MEM_OBJECT] memory object is not a " \ - "valid OpenCL memory object.", \ - __LINE__, __FILE__,M); \ - goto error; \ - case -45: \ - fprintf(stderr, "Open CL Runtime Error: %d (%s) on Line %d in %s\n", \ - retval, "[CL_INVALID_PROGRAM_EXECUTABLE] no successfully " \ - "built program executable available for device " \ - "associated with command_queue.", \ - __LINE__, __FILE__); \ - goto error; \ - case -54: \ - fprintf(stderr, "Open CL Runtime Error: %d (%s) on Line %d in %s\n", \ - retval, "[CL_INVALID_WORK_GROUP_SIZE]", \ - __LINE__, __FILE__); \ - goto error; \ - default: \ - fprintf(stderr, "Open CL Runtime Error: %d (%s) on Line %d in %s\n", \ - retval, M, __LINE__, __FILE__); \ - goto error; \ - } \ -} while(0) - - -#define CHECK_MALLOC_ERROR(type, x) do { \ - type * ptr = (type*)(x); \ - if(ptr == NULL) { \ - fprintf(stderr, "Malloc Error for type %s on Line %d in %s", \ - #type, __LINE__, __FILE__); \ - perror(" "); \ - free(ptr); \ - ptr = NULL; \ - goto malloc_error; \ - } \ -} while(0) - - -#define CHECK_DPGLUE_ERROR(x, M) do { \ - int retval = (x); \ - switch(retval) { \ - case 0: \ - break; \ - case -1: \ - fprintf(stderr, "DP_Glue Error: %d (%s) on Line %d in %s\n", \ - retval, M, __LINE__, __FILE__); \ - goto error; \ - default: \ - fprintf(stderr, "DP_Glue Error: %d (%s) on Line %d in %s\n", \ - retval, M, __LINE__, __FILE__); \ - goto error; \ - } \ -} while(0) diff --git a/backends/source/dppl_opencl_interface.c b/backends/source/dppl_opencl_interface.c deleted file mode 100644 index cf849b32ca..0000000000 --- a/backends/source/dppl_opencl_interface.c +++ /dev/null @@ -1,1166 +0,0 @@ -//===------------ dppl_opencl_interface.c - dpctl-C_API ----*- C -----*----===// -// -// Data Parallel Control Library (dpCtl) -// -// Copyright 2020 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//===----------------------------------------------------------------------===// -/// -/// \file -/// This file implements the data types and functions declared in -/// dppl_opencl_interface.h. -/// -//===----------------------------------------------------------------------===// -#include "dppl_opencl_interface.h" -#include "error_check_macros.h" -#include -#include -#include /* OpenCL headers */ - -/*------------------------------- Magic numbers ------------------------------*/ - -#define RUNTIME_ID 0x6dd5e8c8 -#define ENV_ID 0x6c78fd87 -#define BUFFER_ID 0xc55c47b1 -#define KERNEL_ID 0x032dc08e -#define PROGRAM_ID 0xc3842d12 -#define KERNELARG_ID 0xd42f630f - -#if DEBUG - -static void check_runtime_id (runtime_t x) -{ - assert(x->id_ == RUNTIME_ID); -} - -static void check_env_id (env_t x) -{ - assert(x->id_ == ENV_ID); -} - -static void check_buffer_id (buffer_t x) -{ - assert(x->id_ == BUFFER_ID); -} - -static void check_kernel_id (kernel_t x) -{ - assert(x->id_ == KERNEL_ID); -} - -static void check_program_id (program_t x) -{ - assert(x->id_ == PROGRAM_ID); -} - -static void check_kernelarg_id (kernel_arg_t x) -{ - assert(x->id_ == KERNELARG_ID); -} - -#endif - -/*------------------------------- Private helpers ----------------------------*/ - - -static int get_platform_name (cl_platform_id platform, char **platform_name) -{ - cl_int err; - size_t n; - - err = clGetPlatformInfo(platform, CL_PLATFORM_NAME, 0, *platform_name, &n); - CHECK_OPEN_CL_ERROR(err, "Could not get platform name length."); - - // Allocate memory for the platform name string - *platform_name = (char*)malloc(sizeof(char)*n); - CHECK_MALLOC_ERROR(char*, *platform_name); - - err = clGetPlatformInfo(platform, CL_PLATFORM_NAME, n, *platform_name, - NULL); - CHECK_OPEN_CL_ERROR(err, "Could not get platform name."); - - return DP_GLUE_SUCCESS; - -malloc_error: - return DP_GLUE_FAILURE; -error: - free(*platform_name); - return DP_GLUE_FAILURE; -} - - -/*! - * - */ -static int dump_device_info (void *obj) -{ - cl_int err; - char *value; - size_t size; - cl_uint maxComputeUnits; - env_t env_t_ptr; - - value = NULL; - env_t_ptr = (env_t)obj; - cl_device_id device = (cl_device_id)(env_t_ptr->device); - - err = clRetainDevice(device); - CHECK_OPEN_CL_ERROR(err, "Could not retain device."); - - // print device name - err = clGetDeviceInfo(device, CL_DEVICE_NAME, 0, NULL, &size); - CHECK_OPEN_CL_ERROR(err, "Could not get device name."); - value = (char*)malloc(size); - err = clGetDeviceInfo(device, CL_DEVICE_NAME, size, value, NULL); - CHECK_OPEN_CL_ERROR(err, "Could not get device name."); - printf("Device: %s\n", value); - free(value); - - // print hardware device version - err = clGetDeviceInfo(device, CL_DEVICE_VERSION, 0, NULL, &size); - CHECK_OPEN_CL_ERROR(err, "Could not get device version."); - value = (char*) malloc(size); - err = clGetDeviceInfo(device, CL_DEVICE_VERSION, size, value, NULL); - CHECK_OPEN_CL_ERROR(err, "Could not get device version."); - printf("Hardware version: %s\n", value); - free(value); - - // print software driver version - clGetDeviceInfo(device, CL_DRIVER_VERSION, 0, NULL, &size); - CHECK_OPEN_CL_ERROR(err, "Could not get driver version."); - value = (char*) malloc(size); - clGetDeviceInfo(device, CL_DRIVER_VERSION, size, value, NULL); - CHECK_OPEN_CL_ERROR(err, "Could not get driver version."); - printf("Software version: %s\n", value); - free(value); - - // print c version supported by compiler for device - clGetDeviceInfo(device, CL_DEVICE_OPENCL_C_VERSION, 0, NULL, &size); - CHECK_OPEN_CL_ERROR(err, "Could not get open cl version."); - value = (char*) malloc(size); - clGetDeviceInfo(device, CL_DEVICE_OPENCL_C_VERSION, size, value, NULL); - CHECK_OPEN_CL_ERROR(err, "Could not get open cl version."); - printf("OpenCL C version: %s\n", value); - free(value); - - // print parallel compute units - clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS, - sizeof(maxComputeUnits), &maxComputeUnits, NULL); - CHECK_OPEN_CL_ERROR(err, "Could not get number of compute units."); - printf("Parallel compute units: %d\n", maxComputeUnits); - - err = clReleaseDevice(device); - CHECK_OPEN_CL_ERROR(err, "Could not release device."); - - return DP_GLUE_SUCCESS; - -error: - free(value); - return DP_GLUE_FAILURE; -} - - -/*! - * @brief Helper function to print out information about the platform and - * devices available to this runtime. - * - */ -static int dump_dp_runtime_info (void *obj) -{ - size_t i; - runtime_t rt; - - rt = (runtime_t)obj; -#if DEBUG - check_runtime_id(rt); -#endif - if(rt) { - printf("Number of platforms : %d\n", rt->num_platforms); - cl_platform_id *platforms = rt->platform_ids; - for(i = 0; i < rt->num_platforms; ++i) { - char *platform_name = NULL; - get_platform_name(platforms[i], &platform_name); - printf("Platform #%zu: %s\n", i, platform_name); - free(platform_name); - } - } - - return DP_GLUE_SUCCESS; -} - - -/*! - * - */ -static int dump_dp_kernel_info (void *obj) -{ - cl_int err; - char *value; - size_t size; - cl_uint numKernelArgs; - cl_kernel kernel; - kernel_t kernel_t_ptr; - - value = NULL; - kernel_t_ptr = (kernel_t)obj; -#if DEBUG - check_kernel_id(kernel_t_ptr); -#endif - kernel = (cl_kernel)(kernel_t_ptr->kernel); - - // print kernel function name - err = clGetKernelInfo(kernel, CL_KERNEL_FUNCTION_NAME, 0, NULL, &size); - CHECK_OPEN_CL_ERROR(err, "Could not get kernel function name size."); - value = (char*)malloc(size); - err = clGetKernelInfo(kernel, CL_KERNEL_FUNCTION_NAME, size, value, NULL); - CHECK_OPEN_CL_ERROR(err, "Could not get kernel function name."); - printf("Kernel Function name: %s\n", value); - free(value); - - // print the number of kernel args - err = clGetKernelInfo(kernel, CL_KERNEL_NUM_ARGS, sizeof(numKernelArgs), - &numKernelArgs, NULL); - CHECK_OPEN_CL_ERROR(err, "Could not get kernel num args."); - printf("Number of kernel arguments : %d\n", numKernelArgs); - - return DP_GLUE_SUCCESS; - -error: - free(value); - return DP_GLUE_FAILURE; -} - - -/*! - * - */ -static int get_first_device (cl_platform_id* platforms, - cl_uint platformCount, - cl_device_id *device, - cl_device_type device_ty) -{ - cl_int status; - cl_uint ndevices = 0; - unsigned int i; - - for (i = 0; i < platformCount; ++i) { - // get all devices of env_ty - status = clGetDeviceIDs(platforms[i], device_ty, 0, NULL, &ndevices); - // If this platform has no devices of this type then continue - if(!ndevices) continue; - - // get the first device - status = clGetDeviceIDs(platforms[i], device_ty, 1, device, NULL); - CHECK_OPEN_CL_ERROR(status, "Could not get first cl_device_id."); - - // If the first device of this type was discovered, no need to look more - if(ndevices) break; - } - - if(ndevices) - return DP_GLUE_SUCCESS; - else - return DP_GLUE_FAILURE; - -error: - return DP_GLUE_FAILURE; -} - -static int support_int64_atomics(cl_device_id *device) -{ - - cl_int err; - size_t size; - char *value; - - err = clGetDeviceInfo(*device, CL_DEVICE_EXTENSIONS, 0, NULL, &size); - if (err != CL_SUCCESS ) { - printf("Unable to obtain device info for param\n"); - return DP_GLUE_FAILURE; - } - value = (char*) malloc(size); - clGetDeviceInfo(*device, CL_DEVICE_EXTENSIONS, size, value, NULL); - - if(strstr(value, "cl_khr_int64_base_atomics") != NULL) { - return DP_GLUE_SUCCESS; - } else { - return DP_GLUE_FAILURE; - } -} - -static int support_float64_atomics(cl_device_id *device) -{ - - cl_int err; - size_t size; - char *value; - - err = clGetDeviceInfo(*device, CL_DEVICE_EXTENSIONS, 0, NULL, &size); - if (err != CL_SUCCESS ) { - printf("Unable to obtain device info for param\n"); - return DP_GLUE_FAILURE; - } - value = (char*) malloc(size); - clGetDeviceInfo(*device, CL_DEVICE_EXTENSIONS, size, value, NULL); - - if(strstr(value, "cl_khr_fp64") != NULL) { - return DP_GLUE_SUCCESS; - } else { - return DP_GLUE_FAILURE; - } -} - -/*! - * - */ -static int create_dp_env_t (cl_platform_id* platforms, - size_t nplatforms, - cl_device_type device_ty, - env_t *env_t_ptr) -{ - cl_int err; - int err1; - env_t env; - cl_device_id *device; - - env = NULL; - device = NULL; - - // Allocate the env_t object - env = (env_t)malloc(sizeof(struct dp_env)); - CHECK_MALLOC_ERROR(env_t, env); - env->id_ = ENV_ID; - - env->context = NULL; - env->device = NULL; - env->queue = NULL; - env->max_work_item_dims = 0; - env->max_work_group_size = 0; - env->dump_fn = NULL; - - device = (cl_device_id*)malloc(sizeof(cl_device_id)); - - err1 = get_first_device(platforms, nplatforms, device, device_ty); - CHECK_DPGLUE_ERROR(err1, "Failed inside get_first_device"); - - // get the CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS for this device - err = clGetDeviceInfo(*device, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, - sizeof(env->max_work_item_dims), &env->max_work_item_dims, NULL); - CHECK_OPEN_CL_ERROR(err, "Could not get max work item dims"); - - // get the CL_DEVICE_MAX_WORK_GROUP_SIZE for this device - err = clGetDeviceInfo(*device, CL_DEVICE_MAX_WORK_GROUP_SIZE, - sizeof(env->max_work_group_size), &env->max_work_group_size, NULL); - CHECK_OPEN_CL_ERROR(err, "Could not get max work group size"); - - // Create a context and associate it with device - env->context = clCreateContext(NULL, 1, device, NULL, NULL, &err); - CHECK_OPEN_CL_ERROR(err, "Could not create device context."); - // Create a queue and associate it with the context - env->queue = clCreateCommandQueueWithProperties((cl_context)env->context, - *device, 0, &err); - - CHECK_OPEN_CL_ERROR(err, "Could not create command queue."); - - env->device = *device; - env ->dump_fn = dump_device_info; - - if (DP_GLUE_SUCCESS == support_int64_atomics(device)) { - env->support_int64_atomics = 1; - } else { - env->support_int64_atomics = 0; - } - - if (DP_GLUE_SUCCESS == support_float64_atomics(device)) { - env->support_float64_atomics = 1; - } else { - env->support_float64_atomics = 0; - } - - free(device); - *env_t_ptr = env; - - return DP_GLUE_SUCCESS; - -malloc_error: - return DP_GLUE_FAILURE; -error: - free(env); - *env_t_ptr = NULL; - return DP_GLUE_FAILURE; -} - - -static int destroy_dp_env_t (env_t *env_t_ptr) -{ - cl_int err; -#if DEBUG - check_env_id(*env_t_ptr); -#endif - err = clReleaseCommandQueue((cl_command_queue)(*env_t_ptr)->queue); - CHECK_OPEN_CL_ERROR(err, "Could not release command queue."); - err = clReleaseDevice((cl_device_id)(*env_t_ptr)->device); - CHECK_OPEN_CL_ERROR(err, "Could not release device."); - err = clReleaseContext((cl_context)(*env_t_ptr)->context); - CHECK_OPEN_CL_ERROR(err, "Could not release context."); - - free(*env_t_ptr); - - return DP_GLUE_SUCCESS; - -error: - return DP_GLUE_FAILURE; -} - - -/*! - * @brief Initialize the runtime object. - */ -static int init_runtime_t_obj (runtime_t rt) -{ - cl_int status; - int ret; - cl_platform_id *platforms; -#if DEBUG - check_runtime_id(rt); -#endif - // get count of available platforms - status = clGetPlatformIDs(0, NULL, &(rt->num_platforms)); - CHECK_OPEN_CL_ERROR(status, "Could not get platform count."); - - if(!rt->num_platforms) { - fprintf(stderr, "No OpenCL platforms found.\n"); - goto error; - } - - // Allocate memory for the platforms array - rt->platform_ids = (cl_platform_id*)malloc( - sizeof(cl_platform_id)*rt->num_platforms - ); - CHECK_MALLOC_ERROR(cl_platform_id, rt->platform_ids); - - // Get the platforms - status = clGetPlatformIDs(rt->num_platforms, rt->platform_ids, NULL); - CHECK_OPEN_CL_ERROR(status, "Could not get platform ids"); - // Cast rt->platforms to a pointer of type cl_platform_id, as we cannot do - // pointer arithmetic on void*. - platforms = (cl_platform_id*)rt->platform_ids; - // Get the first cpu device on this platform - ret = create_dp_env_t(platforms, rt->num_platforms, - CL_DEVICE_TYPE_CPU, &rt->first_cpu_env); - rt->has_cpu = !ret; - -#if DEBUG - if(rt->has_cpu) - printf("DEBUG: CPU device acquired...\n"); - else - printf("DEBUG: No CPU available on the system\n"); -#endif - - // Get the first gpu device on this platform - ret = create_dp_env_t(platforms, rt->num_platforms, - CL_DEVICE_TYPE_GPU, &rt->first_gpu_env); - rt->has_gpu = !ret; - -#if DEBUG - if(rt->has_gpu) - printf("DEBUG: GPU device acquired...\n"); - else - printf("DEBUG: No GPU available on the system.\n"); -#endif - - if(rt->has_gpu) - rt->curr_env = rt->first_gpu_env; - else if(rt->has_cpu) - rt->curr_env = rt->first_cpu_env; - else - goto error; - - return DP_GLUE_SUCCESS; - -malloc_error: - - return DP_GLUE_FAILURE; -error: - free(rt->platform_ids); - - return DP_GLUE_FAILURE; -} - -/*-------------------------- End of private helpers --------------------------*/ - -int set_curr_env (runtime_t rt, env_t env) -{ - if(env && rt) { - rt->curr_env = env; - return DP_GLUE_SUCCESS; - } - return DP_GLUE_FAILURE; -} - -/*! - * @brief Initializes a new dp_runtime_t object - * - */ -int create_dp_runtime (runtime_t *rt) -{ - int err; - runtime_t rtobj; - - rtobj = NULL; - // Allocate a new struct dp_runtime object - rtobj = (runtime_t)malloc(sizeof(struct dp_runtime)); - CHECK_MALLOC_ERROR(runtime_t, rt); - - rtobj->id_ = RUNTIME_ID; - rtobj->num_platforms = 0; - rtobj->platform_ids = NULL; - err = init_runtime_t_obj(rtobj); - CHECK_DPGLUE_ERROR(err, "Could not initialize runtime object."); - rtobj->dump_fn = dump_dp_runtime_info; - - *rt = rtobj; -#if DEBUG - printf("DEBUG: Created an new dp_runtime object\n"); -#endif - return DP_GLUE_SUCCESS; - -malloc_error: - return DP_GLUE_FAILURE; -error: - free(rtobj); - return DP_GLUE_FAILURE; -} - - -/*! - * @brief Free the runtime and all its resources. - * - */ -int destroy_dp_runtime (runtime_t *rt) -{ - int err; -#if DEBUG - check_runtime_id(*rt); -#endif - -#if DEBUG - printf("DEBUG: Going to destroy the dp_runtime object\n"); -#endif - // free the first_cpu_device - if((*rt)->first_cpu_env) { - err = destroy_dp_env_t(&(*rt)->first_cpu_env); - CHECK_DPGLUE_ERROR(err, "Could not destroy first_cpu_device."); - } - - // free the first_gpu_device - if((*rt)->first_gpu_env) { - err = destroy_dp_env_t(&(*rt)->first_gpu_env); - CHECK_DPGLUE_ERROR(err, "Could not destroy first_gpu_device."); - } - - // free the platforms - free((cl_platform_id*)(*rt)->platform_ids); - // free the runtime_t object - free(*rt); - -#if DEBUG - printf("DEBUG: Destroyed the new dp_runtime object\n"); -#endif - return DP_GLUE_SUCCESS; - -error: - return DP_GLUE_FAILURE; -} - - -/*! - * - */ -int retain_dp_context (env_t env_t_ptr) -{ - cl_int err; - cl_context context; -#if DEBUG - check_env_id(env_t_ptr); -#endif - context = (cl_context)(env_t_ptr->context); - err = clRetainContext(context); - CHECK_OPEN_CL_ERROR(err, "Failed when calling clRetainContext."); - - return DP_GLUE_SUCCESS; -error: - return DP_GLUE_FAILURE; -} - - -/*! - * - */ -int release_dp_context (env_t env_t_ptr) -{ - cl_int err; - cl_context context; -#if DEBUG - check_env_id(env_t_ptr); -#endif - context = (cl_context)(env_t_ptr->context); - err = clReleaseContext(context); - CHECK_OPEN_CL_ERROR(err, "Failed when calling clRetainContext."); - - return DP_GLUE_SUCCESS; -error: - return DP_GLUE_FAILURE; -} - - -int create_dp_rw_mem_buffer (env_t env_t_ptr, - size_t buffsize, - buffer_t *buffer_t_ptr) -{ - cl_int err; - buffer_t buff; - cl_context context; -#if DEBUG - check_env_id(env_t_ptr); -#endif - buff = NULL; - - // Get the context from the device - context = (cl_context)(env_t_ptr->context); - err = clRetainContext(context); - CHECK_OPEN_CL_ERROR(err, "Failed to retain context."); - - // Allocate a dp_buffer object - buff = (buffer_t)malloc(sizeof(struct dp_buffer)); - CHECK_MALLOC_ERROR(buffer_t, buffer_t_ptr); - - buff->id_ = BUFFER_ID; - - // Create the OpenCL buffer. - // NOTE : Copying of data from host to device needs to happen explicitly - // using clEnqueue[Write|Read]Buffer. This would change in the future. - buff->buffer_ptr = clCreateBuffer(context, CL_MEM_READ_WRITE, buffsize, - NULL, &err); - CHECK_OPEN_CL_ERROR(err, "Failed to create CL buffer."); - - buff->sizeof_buffer_ptr = sizeof(cl_mem); -#if DEBUG - printf("DEBUG: CL RW buffer created...\n"); -#endif - *buffer_t_ptr = buff; - err = clReleaseContext(context); - CHECK_OPEN_CL_ERROR(err, "Failed to release context."); - - return DP_GLUE_SUCCESS; - -malloc_error: - return DP_GLUE_FAILURE; -error: - free(buff); - return DP_GLUE_FAILURE; -} - - -int destroy_dp_rw_mem_buffer (buffer_t *buff) -{ - cl_int err; -#if DEBUG - check_buffer_id(*buff); -#endif - err = clReleaseMemObject((cl_mem)(*buff)->buffer_ptr); - CHECK_OPEN_CL_ERROR(err, "Failed to release CL buffer."); - free(*buff); - -#if DEBUG - printf("DEBUG: CL buffer destroyed...\n"); -#endif - - return DP_GLUE_SUCCESS; - -error: - return DP_GLUE_FAILURE; -} - - -int write_dp_mem_buffer_to_device (env_t env_t_ptr, - buffer_t buffer_t_ptr, - bool blocking, - size_t offset, - size_t buffersize, - const void *data_ptr) -{ - cl_int err; - cl_command_queue queue; - cl_mem mem; -#if DEBUG - check_env_id(env_t_ptr); - check_buffer_id(buffer_t_ptr); -#endif - queue = (cl_command_queue)env_t_ptr->queue; - mem = (cl_mem)buffer_t_ptr->buffer_ptr; - -#if DEBUG - assert(mem && "buffer memory is NULL"); -#endif - - err = clRetainMemObject(mem); - CHECK_OPEN_CL_ERROR(err, "Failed to retain the command queue."); - err = clRetainCommandQueue(queue); - CHECK_OPEN_CL_ERROR(err, "Failed to retain the buffer memory object."); - - // Not using any events for the time being. Eventually we want to figure - // out the event dependencies using parfor analysis. - err = clEnqueueWriteBuffer(queue, mem, blocking?CL_TRUE:CL_FALSE, - offset, buffersize, data_ptr, 0, NULL, NULL); - CHECK_OPEN_CL_ERROR(err, "Failed to write to CL buffer."); - - err = clReleaseCommandQueue(queue); - CHECK_OPEN_CL_ERROR(err, "Failed to release the command queue."); - err = clReleaseMemObject(mem); - CHECK_OPEN_CL_ERROR(err, "Failed to release the buffer memory object."); - -#if DEBUG - printf("DEBUG: CL buffer written to device...\n"); -#endif - //--- TODO: Implement a version that uses clEnqueueMapBuffer - - return DP_GLUE_SUCCESS; -error: - return DP_GLUE_FAILURE; -} - - -int read_dp_mem_buffer_from_device (env_t env_t_ptr, - buffer_t buffer_t_ptr, - bool blocking, - size_t offset, - size_t buffersize, - void *data_ptr) -{ - cl_int err; - cl_command_queue queue; - cl_mem mem; -#if DEBUG - check_env_id(env_t_ptr); - check_buffer_id(buffer_t_ptr); -#endif - queue = (cl_command_queue)env_t_ptr->queue; - mem = (cl_mem)buffer_t_ptr->buffer_ptr; - - err = clRetainMemObject(mem); - CHECK_OPEN_CL_ERROR(err, "Failed to retain the command queue."); - err = clRetainCommandQueue(queue); - CHECK_OPEN_CL_ERROR(err, "Failed to retain the command queue."); - - // Not using any events for the time being. Eventually we want to figure - // out the event dependencies using parfor analysis. - err = clEnqueueReadBuffer(queue, mem, blocking?CL_TRUE:CL_FALSE, - offset, buffersize, data_ptr, 0, NULL, NULL); - CHECK_OPEN_CL_ERROR(err, "Failed to read from CL buffer."); - - err = clReleaseCommandQueue(queue); - CHECK_OPEN_CL_ERROR(err, "Failed to release the command queue."); - err = clReleaseMemObject(mem); - CHECK_OPEN_CL_ERROR(err, "Failed to release the buffer memory object."); - -#if DEBUG - printf("DEBUG: CL buffer read from device...\n"); -#endif - fflush(stdout); - //--- TODO: Implement a version that uses clEnqueueMapBuffer - - return DP_GLUE_SUCCESS; -error: - return DP_GLUE_FAILURE; -} - - -int create_dp_program_from_spirv (env_t env_t_ptr, - const void *il, - size_t length, - program_t *program_t_ptr) -{ - cl_int err; - cl_context context; - program_t prog; -#if DUMP_SPIRV - FILE *write_file; -#endif -#if DEBUG - check_env_id(env_t_ptr); -#endif - prog = NULL; - -#if DUMP_SPIRV - write_file = fopen("latest.spirv","wb"); - fwrite(il,length,1,write_file); - fclose(write_file); -#endif - - prog = (program_t)malloc(sizeof(struct dp_program)); - CHECK_MALLOC_ERROR(program_t, program_t_ptr); - - prog->id_ = PROGRAM_ID; - - context = (cl_context)env_t_ptr->context; - - err = clRetainContext(context); - CHECK_OPEN_CL_ERROR(err, "Could not retain context"); - // Create a program with a SPIR-V file - prog->program = clCreateProgramWithIL(context, il, length, &err); - CHECK_OPEN_CL_ERROR(err, "Could not create program with IL"); -#if DEBUG - printf("DEBUG: CL program created from spirv of length %zu...\n", length); -#endif - - *program_t_ptr = prog; - - err = clReleaseContext(context); - CHECK_OPEN_CL_ERROR(err, "Could not release context"); - - return DP_GLUE_SUCCESS; - -malloc_error: - return DP_GLUE_FAILURE; -error: - free(prog); - return DP_GLUE_FAILURE; -} - - -int create_dp_program_from_source (env_t env_t_ptr, - unsigned int count, - const char **strings, - const size_t *lengths, - program_t *program_t_ptr) -{ - cl_int err; - cl_context context; - program_t prog; -#if DEBUG - check_env_id(env_t_ptr); -#endif - prog = NULL; - prog = (program_t)malloc(sizeof(struct dp_program)); - CHECK_MALLOC_ERROR(program_t, program_t_ptr); - - prog->id_ = PROGRAM_ID; - - context = (cl_context)env_t_ptr->context; - - err = clRetainContext(context); - CHECK_OPEN_CL_ERROR(err, "Could not retain context"); - // Create a program with string source files - prog->program = clCreateProgramWithSource(context, count, strings, - lengths, &err); - CHECK_OPEN_CL_ERROR(err, "Could not create program with source"); -#if DEBUG - printf("DEBUG: CL program created from source...\n"); -#endif - - *program_t_ptr = prog; - - err = clReleaseContext(context); - CHECK_OPEN_CL_ERROR(err, "Could not release context"); - - return DP_GLUE_SUCCESS; - -malloc_error: - return DP_GLUE_FAILURE; -error: - free(prog); - return DP_GLUE_FAILURE; -} - - -int destroy_dp_program (program_t *program_ptr) -{ - cl_int err; -#if DEBUG - check_program_id(*program_ptr); -#endif - err = clReleaseProgram((cl_program)(*program_ptr)->program); - CHECK_OPEN_CL_ERROR(err, "Failed to release CL program."); - free(*program_ptr); - -#if DEBUG - printf("DEBUG: CL program destroyed...\n"); -#endif - - return DP_GLUE_SUCCESS; - -error: - return DP_GLUE_FAILURE; -} - - -int build_dp_program (env_t env_t_ptr, program_t program_t_ptr) -{ - cl_int err; - cl_device_id device; -#if DEBUG - check_env_id(env_t_ptr); - check_program_id(program_t_ptr); -#endif - device = (cl_device_id)env_t_ptr->device; - err = clRetainDevice(device); - CHECK_OPEN_CL_ERROR(err, "Could not retain device"); - // Build (compile) the program for the device - err = clBuildProgram((cl_program)program_t_ptr->program, 1, &device, NULL, - NULL, NULL); - CHECK_OPEN_CL_ERROR(err, "Could not build program"); -#if DEBUG - printf("DEBUG: CL program successfully built.\n"); -#endif - err = clReleaseDevice(device); - CHECK_OPEN_CL_ERROR(err, "Could not release device"); - - return DP_GLUE_SUCCESS; - -error: - return DP_GLUE_FAILURE; -} - - -/*! - * - */ -int create_dp_kernel (env_t env_t_ptr, - program_t program_t_ptr, - const char *kernel_name, - kernel_t *kernel_ptr) -{ - cl_int err; - cl_context context; - kernel_t ker; -#if DEBUG - check_env_id(env_t_ptr); -#endif - ker = NULL; - ker = (kernel_t)malloc(sizeof(struct dp_kernel)); - CHECK_MALLOC_ERROR(kernel_t, kernel_ptr); - - ker->id_ = KERNEL_ID; - - context = (cl_context)(env_t_ptr->context); - err = clRetainContext(context); - CHECK_OPEN_CL_ERROR(err, "Could not retain context"); - ker->kernel = clCreateKernel((cl_program)(program_t_ptr->program), - kernel_name, &err); - CHECK_OPEN_CL_ERROR(err, "Could not create kernel"); - err = clReleaseContext(context); - CHECK_OPEN_CL_ERROR(err, "Could not release context"); -#if DEBUG - printf("DEBUG: CL kernel created\n"); -#endif - ker->dump_fn = dump_dp_kernel_info; - *kernel_ptr = ker; - return DP_GLUE_SUCCESS; - -malloc_error: - return DP_GLUE_FAILURE; -error: - free(ker); - return DP_GLUE_FAILURE; -} - - -int destroy_dp_kernel (kernel_t *kernel_ptr) -{ - cl_int err; -#if DEBUG - check_kernel_id(*kernel_ptr); -#endif - err = clReleaseKernel((cl_kernel)(*kernel_ptr)->kernel); - CHECK_OPEN_CL_ERROR(err, "Failed to release CL kernel."); - free(*kernel_ptr); - -#if DEBUG - printf("DEBUG: CL kernel destroyed...\n"); -#endif - - return DP_GLUE_SUCCESS; - -error: - return DP_GLUE_FAILURE; -} - - -/*! - * - */ -int create_dp_kernel_arg (const void *arg_value, - size_t arg_size, - kernel_arg_t *kernel_arg_t_ptr) -{ - kernel_arg_t kernel_arg; - - kernel_arg = NULL; - kernel_arg = (kernel_arg_t)malloc(sizeof(struct dp_kernel_arg)); - CHECK_MALLOC_ERROR(kernel_arg_t, kernel_arg); - - kernel_arg->id_ = KERNELARG_ID; - kernel_arg->arg_size = arg_size; - kernel_arg->arg_value = arg_value; - -#if DEBUG - printf("DEBUG: Kernel arg created\n"); -// void **tp = (void**)kernel_arg->arg_value; -// printf("DEBUG: create_kernel_arg %p (size %ld, addr %p)\n", -// kernel_arg, kernel_arg->arg_size, *tp); -#endif - - *kernel_arg_t_ptr = kernel_arg; - - return DP_GLUE_SUCCESS; - -malloc_error: - return DP_GLUE_FAILURE; -} - -/*! - * - */ -int create_dp_kernel_arg_from_buffer (buffer_t *buffer_t_ptr, - kernel_arg_t *kernel_arg_t_ptr) -{ -#if DEBUG - check_buffer_id(*buffer_t_ptr); -#endif - return create_dp_kernel_arg(&((*buffer_t_ptr)->buffer_ptr), - (*buffer_t_ptr)->sizeof_buffer_ptr, - kernel_arg_t_ptr); -} - -/*! - * - */ -int destroy_dp_kernel_arg (kernel_arg_t *kernel_arg_t_ptr) -{ - free(*kernel_arg_t_ptr); - -#if DEBUG - printf("DEBUG: Kernel arg destroyed...\n"); -#endif - - return DP_GLUE_SUCCESS; -} - - -/*! - * - */ -int set_args_and_enqueue_dp_kernel (env_t env_t_ptr, - kernel_t kernel_t_ptr, - size_t nargs, - const kernel_arg_t *array_of_args, - unsigned int work_dim, - const size_t *global_work_offset, - const size_t *global_work_size, - const size_t *local_work_size) -{ - size_t i; - cl_int err; - cl_kernel kernel; - cl_command_queue queue; - - err = 0; -#if DEBUG - check_env_id(env_t_ptr); - check_kernel_id(kernel_t_ptr); -#endif - kernel = (cl_kernel)kernel_t_ptr->kernel; - queue = (cl_command_queue)env_t_ptr->queue; -#if DEBUG - kernel_t_ptr->dump_fn(kernel_t_ptr); -#endif - // Set the kernel arguments - for(i = 0; i < nargs; ++i) { -#if DEBUG - printf("DEBUG: clSetKernelArgs for arg # %zu\n", i); -#endif - kernel_arg_t this_arg = array_of_args[i]; -#if DEBUG - check_kernelarg_id(this_arg); - void **tp = (void**)this_arg->arg_value; - printf("DEBUG: clSetKernelArgs for arg # %zu (size %zu, addr %p)\n", i, - this_arg->arg_size, *tp); -#endif - err = clSetKernelArg(kernel, i, this_arg->arg_size, - this_arg->arg_value); - CHECK_OPEN_CL_ERROR(err, "Could not set arguments to the kernel"); - } - - // Execute the kernel. Not using events for the time being. - err = clEnqueueNDRangeKernel(queue, kernel, work_dim, global_work_offset, - global_work_size, local_work_size, 0, NULL, NULL); - CHECK_OPEN_CL_ERROR(err, "Could not enqueue the kernel"); - - err = clFinish(queue); - CHECK_OPEN_CL_ERROR(err, "Failed while waiting for queue to finish"); -#if DEBUG - printf("DEBUG: CL Kernel Finish...\n"); -#endif - return DP_GLUE_SUCCESS; - -error: - return DP_GLUE_FAILURE; -} - - -/*! - * - */ -int set_args_and_enqueue_dp_kernel_auto_blocking (env_t env_t_ptr, - kernel_t kernel_t_ptr, - size_t nargs, - const kernel_arg_t *args, - unsigned int num_dims, - size_t *dim_starts, - size_t *dim_stops) -{ - size_t *global_work_size; -// size_t *local_work_size; - int err; - unsigned i; - - global_work_size = (size_t*)malloc(sizeof(size_t) * num_dims); -// local_work_size = (size_t*)malloc(sizeof(size_t) * num_dims); - CHECK_MALLOC_ERROR(size_t, global_work_size); -// CHECK_MALLOC_ERROR(size_t, local_work_size); - - assert(num_dims > 0 && num_dims < 4); - for (i = 0; i < num_dims; ++i) { - global_work_size[i] = dim_stops[i] - dim_starts[i] + 1; - } - - err = set_args_and_enqueue_dp_kernel(env_t_ptr, - kernel_t_ptr, - nargs, - args, - num_dims, - NULL, - global_work_size, - NULL); - free(global_work_size); -// free(local_work_size); - return err; - -malloc_error: - free(global_work_size); -// free(local_work_size); - return DP_GLUE_FAILURE; -} diff --git a/conda-recipe/bld.bat b/conda-recipe/bld.bat index a44c3dabb0..1d811447a8 100644 --- a/conda-recipe/bld.bat +++ b/conda-recipe/bld.bat @@ -35,11 +35,6 @@ mkdir dpctl\include xcopy backends\include dpctl\include /E /Y -REM required by _opencl_core (dpctl.ocldrv) -set "DPPL_OPENCL_INTERFACE_LIBDIR=dpctl" -set "DPPL_OPENCL_INTERFACE_INCLDIR=dpctl\include" -set "OpenCL_LIBDIR=%DPCPP_ROOT%\lib" - REM required by _sycl_core(dpctl) set "DPPL_SYCL_INTERFACE_LIBDIR=dpctl" set "DPPL_SYCL_INTERFACE_INCLDIR=dpctl\include" diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh index 72c28d711d..607da35268 100755 --- a/conda-recipe/build.sh +++ b/conda-recipe/build.sh @@ -40,10 +40,6 @@ cp install/lib/*.so dpctl/ mkdir -p dpctl/include cp -r backends/include/* dpctl/include -# required by dpctl.opencl_core -export DPPL_OPENCL_INTERFACE_LIBDIR=dpctl -export DPPL_OPENCL_INTERFACE_INCLDIR=dpctl/include -export OpenCL_LIBDIR=${DPCPP_ROOT}/lib # required by dpctl.sycl_core export DPPL_SYCL_INTERFACE_LIBDIR=dpctl @@ -53,6 +49,5 @@ export DPPL_SYCL_INTERFACE_INCLDIR=dpctl/include # FIXME: How to pass this using setup.py? This flags is needed when # dpcpp compiles the generated cpp file. export CFLAGS="-fPIC -O3 ${CFLAGS}" -export LDFLAGS="-L ${OpenCL_LIBDIR} ${LDFLAGS}" ${PYTHON} setup.py clean --all ${PYTHON} setup.py build install diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml index f48cccc14f..acf485898a 100644 --- a/conda-recipe/meta.yaml +++ b/conda-recipe/meta.yaml @@ -17,7 +17,6 @@ requirements: - {{ compiler('cxx') }} host: - setuptools - - cffi >=1.0.0 - cython - cmake - python @@ -27,7 +26,6 @@ requirements: run: - python - numpy >=1.17 - - cffi >=1.0.0 about: home: https://github.com/IntelPython/dpCtl.git diff --git a/conda-recipe/run_test.bat b/conda-recipe/run_test.bat index 992277b497..ed3a395aec 100644 --- a/conda-recipe/run_test.bat +++ b/conda-recipe/run_test.bat @@ -8,8 +8,5 @@ set ERRORLEVEL= "%PYTHON%" -c "import dpctl" IF %ERRORLEVEL% NEQ 0 exit 1 -"%PYTHON%" -c "import dpctl.ocldrv" -IF %ERRORLEVEL% NEQ 0 exit 1 - "%PYTHON%" -m unittest -v dpctl.tests IF %ERRORLEVEL% NEQ 0 exit 1 diff --git a/conda-recipe/run_test.sh b/conda-recipe/run_test.sh index 775783ce50..ff46be6632 100644 --- a/conda-recipe/run_test.sh +++ b/conda-recipe/run_test.sh @@ -6,5 +6,4 @@ set -e source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh || true ${PYTHON} -c "import dpctl" -${PYTHON} -c "import dpctl.ocldrv" ${PYTHON} -m unittest -v dpctl.tests diff --git a/dpctl/ocldrv.py b/dpctl/ocldrv.py deleted file mode 100644 index c41269bc90..0000000000 --- a/dpctl/ocldrv.py +++ /dev/null @@ -1,705 +0,0 @@ -##===------------- ocldrv.py - dpctl.ocldrv module ------*- Python -*------===## -## -## Data Parallel Control (dpCtl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -### -### \file -### This file exposes Python classes for different OpenCL classes that are -### exposed by the _opencl_core CFFI extension module. -##===----------------------------------------------------------------------===## -""" The dpctl.ocldrv module contains a set of Python wrapper classes for - OpenCL objects. The module has wrappers for cl_context, cl_device, - cl_mem, cl_program, and cl_kernel objects. - - The two main user-visible API classes are Runtime, DeviceArray, and - DeviceEnv and Runtime. The other classes are only used by the Numba - JIT compiler. - - Global data members: - runtime - An instance of the Runtime class. - has_cpu_device - A flag set to True when an OpenCL CPU device is found - on the system. - has_cpu_device - A flag set to True when an OpenCL GPU device is found - on the system. - -""" - -from __future__ import absolute_import, division, print_function - -from contextlib import contextmanager -import ctypes -import logging - -from numpy import ndarray - -from ._opencl_core import ffi, lib - - -__author__ = "Intel Corp." - -_logger = logging.getLogger(__name__) - -# create console handler and set level to debug -_ch = logging.StreamHandler() -_ch.setLevel(logging.WARNING) -# create formatter -_formatter = logging.Formatter("DPPL-%(levelname)s - %(message)s") -# add formatter to ch -_ch.setFormatter(_formatter) -# add ch to logger -_logger.addHandler(_ch) - - -########################################################################## -# Exception classes -########################################################################## - - -class DpplDriverError(Exception): - """The exception is raised when dpctl.ocldrv cannot find an OpenCL Driver.""" - - pass - - -class DeviceNotFoundError(Exception): - """The exception is raised when the requested type of OpenCL device is - not available or not supported by dpctl.ocldrv. - """ - - pass - - -class UnsupportedTypeError(Exception): - """The exception is raised when an unsupported type is encountered when - creating an OpenCL KernelArg. Only DeviceArray or numpy.ndarray types - are supported. - """ - - pass - - -########################################################################## -# Helper functions -########################################################################## - - -def _raise_driver_error(fname, errcode): - e = DpplDriverError( - "Could not find an OpenCL Driver. Ensure OpenCL \ - driver is installed." - ) - e.fname = fname - e.code = errcode - raise e - - -def _raise_device_not_found_error(fname): - e = DeviceNotFoundError("OpenCL device not available on the system.") - e.fname = fname - raise e - - -def _raise_unsupported_type_error(fname): - e = UnsupportedTypeError("Type needs to be DeviceArray or numpy.ndarray.") - e.fname = fname - raise e - - -def _raise_unsupported_kernel_arg_error(fname): - e = UnsupportedTypeError( - "Type needs to be DeviceArray or a supported " "ctypes type." - ) - e.fname = fname - raise e - - -def _is_supported_ctypes_raw_obj(obj): - return isinstance( - obj, - ( - ctypes.c_ssize_t, - ctypes.c_double, - ctypes.c_float, - ctypes.c_uint8, - ctypes.c_size_t, - ), - ) - - -########################################################################## -# DeviceArray class -########################################################################## - - -class DeviceArray: - """A Python wrapper for an OpenCL cl_men buffer with read-write access. A - DeviceArray can only be created from a NumPy ndarray. - """ - - _buffObj = None - _ndarray = None - _buffSize = None - _dataPtr = None - - def __init__(self, env_ptr, arr): - """Creates a new DeviceArray from an ndarray. - - Note that DeviceArray creation only allocates the cl_mem buffer - and does not actually move the data to the device. Data copy from - host to device is done when the DeviceArray instance is passed as - an argument to DeviceEnv.copy_array_to_device(). - """ - - # We only support device buffers for ndarray and ctypes (for basic - # types like int, etc) - if not isinstance(arr, ndarray): - _raise_unsupported_type_error("DeviceArray constructor") - - # create a dp_buffer_t object - self._buffObj = ffi.new("buffer_t *") - self._ndarray = arr - self._buffSize = arr.itemsize * arr.size - self._dataPtr = ffi.cast("void *", arr.ctypes.data) - retval = lib.create_dp_rw_mem_buffer(env_ptr, self._buffSize, self._buffObj) - if retval == -1: - _logger.warning("OpenCL Error Code : %s", retval) - _raise_driver_error("create_dp_rw_mem_buffer", -1) - - def __del__(self): - """ Destroy the DeviceArray and release the OpenCL buffer.""" - - retval = lib.destroy_dp_rw_mem_buffer(self._buffObj) - if retval == -1: - _logger.warning("OpenCL Error Code : %s", retval) - _raise_driver_error("destroy_dp_rw_mem_buffer", -1) - - def get_buffer_obj(self): - """Returns a cdata wrapper object encapsulating an OpenCL buffer.""" - - return self._buffObj - - def get_buffer_size(self): - """Returns the size of the OpenCL buffer in bytes.""" - - return self._buffSize - - def get_buffer_ptr(self): - """Returns a cdata wrapper over the actual OpenCL cl_mem pointer.""" - - return self.get_buffer_obj()[0].buffer_ptr - - def get_data_ptr(self): - """Returns the data pointer for the NumPy ndarray used to create - the DeviceArray object. - """ - - return self._dataPtr - - def get_ndarray(self): - """Returns the NumPy ndarray used to create the DeviceArray object.""" - - return self._ndarray - - -########################################################################## -# Program class -########################################################################## - - -class Program: - def __init__(self, device_env, spirv_module): - self._prog_t_obj = ffi.new("program_t *") - retval = lib.create_dp_program_from_spirv( - device_env.get_env_ptr(), spirv_module, len(spirv_module), self._prog_t_obj - ) - if retval == -1: - _logger.warning("OpenCL Error Code : %s", retval) - _raise_driver_error("create_dp_program_from_spirv", -1) - - retval = lib.build_dp_program(device_env.get_env_ptr(), self._prog_t_obj[0]) - if retval == -1: - _logger.warning("OpenCL Error Code : %s", retval) - _raise_driver_error("build_dp_program", -1) - - def __del__(self): - retval = lib.destroy_dp_program(self._prog_t_obj) - if retval == -1: - _logger.warning("OpenCL Error Code : %s", retval) - _raise_driver_error("destroy_dp_program", -1) - - def get_prog_t_obj(self): - return self._prog_t_obj[0] - - -########################################################################## -# Kernel class -########################################################################## - - -class Kernel: - def __init__(self, device_env, prog_t_obj, kernel_name): - self._kernel_t_obj = ffi.new("kernel_t *") - retval = lib.create_dp_kernel( - device_env.get_env_ptr(), - prog_t_obj.get_prog_t_obj(), - kernel_name.encode(), - self._kernel_t_obj, - ) - if retval == -1: - _logger.warning("OpenCL Error Code : %s", retval) - _raise_driver_error("create_dp_kernel", -1) - - def __del__(self): - retval = lib.destroy_dp_kernel(self._kernel_t_obj) - if retval == -1: - _logger.warning("OpenCL Error Code : %s", retval) - _raise_driver_error("destroy_dp_kernel", -1) - - def get_kernel_t_obj(self): - return self._kernel_t_obj[0] - - def dump(self): - retval = self._kernel_t_obj.dump_fn(self._kernel_t_obj) - if retval == -1: - _raise_driver_error("kernel dump_fn", -1) - - -########################################################################## -# KernelArg class -########################################################################## - - -class KernelArg: - def __init__(self, arg, void_p_arg=False): - self.arg = arg - self.kernel_arg_t = ffi.new("kernel_arg_t *") - if void_p_arg is True: - self.ptr_to_arg_p = ffi.new("void **") - self.ptr_to_arg_p[0] = ffi.cast("void *", 0) - retval = lib.create_dp_kernel_arg( - self.ptr_to_arg_p, ffi.sizeof(self.ptr_to_arg_p), self.kernel_arg_t - ) - if retval: - _raise_driver_error("create_dp_kernel_arg", -1) - else: - if isinstance(arg, DeviceArray): - self.ptr_to_arg_p = ffi.new("void **") - self.ptr_to_arg_p[0] = arg.get_buffer_obj()[0].buffer_ptr - retval = lib.create_dp_kernel_arg( - self.ptr_to_arg_p, - arg.get_buffer_obj()[0].sizeof_buffer_ptr, - self.kernel_arg_t, - ) - if retval: - _raise_driver_error("create_dp_kernel_arg", -1) - else: - # it has to be of type ctypes - if getattr(arg, "__module__", None) == "ctypes": - self.ptr_to_arg_p = ffi.cast("void *", ctypes.addressof(arg)) - retval = lib.create_dp_kernel_arg( - self.ptr_to_arg_p, ctypes.sizeof(arg), self.kernel_arg_t - ) - if retval: - _raise_driver_error("create_dp_kernel_arg", -1) - else: - _logger.warning("Unsupported Type %s", type(arg)) - _raise_unsupported_kernel_arg_error("KernelArg init") - - def __del__(self): - retval = lib.destroy_dp_kernel_arg(self.kernel_arg_t) - if retval == -1: - _logger.warning("OpenCL Error Code : %s", retval) - _raise_driver_error("destroy_dp_kernel_arg", -1) - - def get_kernel_arg_obj(self): - return self.kernel_arg_t[0] - - -########################################################################## -# DeviceEnv class -########################################################################## - - -class DeviceEnv: - """A Python wrapper over an OpenCL cl_context object.""" - - def __init__(self, env_t_obj): - self._env_ptr = env_t_obj - - def __del__(self): - pass - - def retain_context(self): - """Increment the reference count of the OpenCL context object.""" - - retval = lib.retain_dp_context(self._env_ptr.context) - if retval == -1: - _raise_driver_error("retain_dp_context", -1) - - return self._env_ptr.context - - def release_context(self): - """Increment the reference count of the OpenCL context object.""" - - retval = lib.release_dp_context(self._env_ptr.context) - if retval == -1: - _raise_driver_error("release_dp_context", -1) - - def copy_array_to_device(self, array): - """Accepts either a DeviceArray or a NumPy ndarray and copies the - data from host to an OpenCL device buffer. Returns either the - DeviceArray that was passed in as an argument, or for the case of - ndarrays returns a new DeviceArray. - - If the function is called with a DeviceArray argument, the - function performs a blocking write of the data from the - DeviceArray's ndarray member into its OpenCL device buffer member. - When the function is called with an ndarray argument is, a new - DeviceArray is first created. The data copy operation is then - performed on the new DeviceArray. - """ - - if isinstance(array, DeviceArray): - retval = lib.write_dp_mem_buffer_to_device( - self._env_ptr, - array.get_buffer_obj()[0], - True, - 0, - array.get_buffer_size(), - array.get_data_ptr(), - ) - if retval == -1: - _logger.warning("OpenCL Error Code : %s", retval) - _raise_driver_error("write_dp_mem_buffer_to_device", -1) - return array - elif ( - isinstance(array, ndarray) or getattr(array, "__module__", None) == "ctypes" - ): - dArr = DeviceArray(self._env_ptr, array) - retval = lib.write_dp_mem_buffer_to_device( - self._env_ptr, - dArr.get_buffer_obj()[0], - True, - 0, - dArr.get_buffer_size(), - dArr.get_data_ptr(), - ) - if retval == -1: - _logger.warning("OpenCL Error Code : %s", retval) - _raise_driver_error("write_dp_mem_buffer_to_device", -1) - return dArr - else: - _raise_unsupported_type_error("copy_array_to_device") - - def copy_array_from_device(self, array): - """Copies data from a cl_mem buffer into a DeviceArray's host memory - pointer. The function argument should be a DeviceArray object. - """ - - if not isinstance(array, DeviceArray): - _raise_unsupported_type_error("copy_array_to_device") - retval = lib.read_dp_mem_buffer_from_device( - self._env_ptr, - array.get_buffer_obj()[0], - True, - 0, - array.get_buffer_size(), - array.get_data_ptr(), - ) - if retval == -1: - _logger.warning("OpenCL Error Code : %s", retval) - _raise_driver_error("read_dp_mem_buffer_from_device", -1) - - def create_device_array(self, array): - """Returns an new DeviceArray instance.""" - - if not ( - ( - isinstance(array, ndarray) - or getattr(array, "__module__", None) == "ctypes" - ) - ): - _raise_unsupported_type_error("alloc_array_in_device") - - return DeviceArray(self._env_ptr, array) - - def device_support_int64_atomics(self): - """Returns True current device supports 64-bit int atomic operations""" - - return self._env_ptr.support_int64_atomics - - def device_support_float64_atomics(self): - """Returns True if current device supports 64-bit float atomic operations""" - - return self._env_ptr.support_float64_atomics - - def get_context_ptr(self): - """Returns a cdata wrapper for the OpenCL cl_context object.""" - - return self._env_ptr.context - - def get_device_ptr(self): - """Returns a cdata wrapper for the OpenCL cl_device object.""" - - return self._env_ptr.device - - def get_queue_ptr(self): - """Returns a cdata wrapper for the OpenCL cl_command_queue object.""" - - return self._env_ptr.queue - - def get_env_ptr(self): - """Returns a cdata wrapper for a C object encapsulating an OpenCL - cl_device object, a cl_command_queue object, - and a cl_context object. - """ - - return self._env_ptr - - def get_max_work_item_dims(self): - """Returns the maximum number of work items per work group for - the OpenCL device. - """ - - return self._env_ptr.max_work_item_dims - - def get_max_work_group_size(self): - """Returns the max work group size for the OpenCL device.""" - - return self._env_ptr.max_work_group_size - - def dump(self): - """Prints metadata for the underlying OpenCL device.""" - - retval = self._env_ptr[0].dump_fn(self._env_ptr) - if retval == -1: - _raise_driver_error("env dump_fn", -1) - return retval - - -########################################################################## -# Runtime class -########################################################################## - - -class Runtime: - """Runtime is a singleton class that creates a C wrapper object storing - available OpenCL contexts and corresponding OpenCL command queues. The - context and the queue are stored only for the first available GPU and CPU - OpenCL devices found on the system. - """ - - _singleton = None - - def __new__(cls): - obj = cls._singleton - if obj is not None: - return obj - else: - obj = object.__new__(cls) - - cls._lib = lib - cls._ffi = ffi - - ffiobj = ffi.new("runtime_t *") - retval = lib.create_dp_runtime(ffiobj) - if retval: - _logger.warning("OpenCL Error Code : %s", retval) - _raise_driver_error("create_dp_runtime", -1) - - cls._runtime = ffiobj - - if cls._runtime[0][0].has_cpu: - cls._cpu_device = DeviceEnv(cls._runtime[0][0].first_cpu_env) - else: - cls._cpu_device = None - _logger.warning("No CPU device") - - if cls._runtime[0][0].has_gpu: - cls._gpu_device = DeviceEnv(cls._runtime[0][0].first_gpu_env) - else: - cls._gpu_device = None - _logger.warning("No GPU device") - - cls._curr_device = DeviceEnv(cls._runtime[0][0].curr_env) - cls._singleton = obj - - return obj - - def __init__(self): - pass - - def __del__(self): - if self._runtime: - retval = self._lib.destroy_dp_runtime(self._runtime) - if retval: - _raise_driver_error("destroy_dp_runtime", -1) - - def has_cpu_device(self): - """ Returns True is the system has an OpenCL driver for the CPU.""" - - return self._cpu_device is not None - - def has_gpu_device(self): - """ Returns True is the system has an OpenCL driver for the GPU.""" - - return self._gpu_device is not None - - def get_cpu_device(self): - """Returns a cdata wrapper for the first available OpenCL - CPU context. - """ - - if self._cpu_device is None: - _raise_device_not_found_error("get_cpu_device") - - return self._cpu_device - - def get_gpu_device(self): - """Returns a cdata wrapper for the first available OpenCL - GPU context. - """ - - if self._gpu_device is None: - _raise_device_not_found_error("get_gpu_device") - - return self._gpu_device - - def get_current_device(self): - """Returns a cdata wrapper for the first available OpenCL - CPU context. - """ - - return self._curr_device - - def get_runtime_ptr(self): - """Returns a reference to the runtime object.""" - - return self._runtime[0] - - def dump(self): - """Prints OpenCL metadata about the available devices and contexts.""" - - retval = self._runtime[0].dump_fn(Runtime._runtime[0]) - if retval == -1: - _raise_driver_error("runtime dump_fn", -1) - return retval - - -########################################################################## -# Public API -########################################################################## - -# ------- Global Data - -runtime = Runtime() -has_cpu_device = runtime.has_cpu_device() -has_gpu_device = runtime.has_gpu_device() - -# ------- Global Functions - - -def enqueue_kernel(device_env, kernel, kernelargs, global_work_size, local_work_size): - """A single wrapper function over OpenCL clCreateKernelArgs and - clEnqueueNDRangeKernel. The function blocks till the enqueued kernel - finishes execution. - """ - - l_work_size_array = None - kernel_arg_array = ffi.new("kernel_arg_t [" + str(len(kernelargs)) + "]") - g_work_size_array = ffi.new("size_t [" + str(len(global_work_size)) + "]") - if local_work_size: - l_work_size_array = ffi.new("size_t [" + str(len(local_work_size)) + "]") - else: - l_work_size_array = ffi.NULL - for i in range(len(kernelargs)): - kernel_arg_array[i] = kernelargs[i].get_kernel_arg_obj() - for i in range(len(global_work_size)): - g_work_size_array[i] = global_work_size[i] - for i in range(len(local_work_size)): - l_work_size_array[i] = local_work_size[i] - retval = lib.set_args_and_enqueue_dp_kernel( - device_env.get_env_ptr(), - kernel.get_kernel_t_obj(), - len(kernelargs), - kernel_arg_array, - len(global_work_size), - ffi.NULL, - g_work_size_array, - l_work_size_array, - ) - if retval: - _raise_driver_error("set_args_and_enqueue_dp_kernel", -1) - - -def is_available(): - """Return a Boolean to indicate the availability of a DPPL device.""" - - return runtime.has_cpu_device() or runtime.has_gpu_device() - - -def dppl_error(): - """Raised a DpplDriverError exception.""" - - _raise_driver_error() - - -########################################################################## -# Context Managers -########################################################################## - - -@contextmanager -def igpu_context(*args, **kwds): - """A context manager sets the current DeviceEnv inside the global - runtime object to the default GPU DeviceEnv. The GPU DeviceEnv is - yielded by the context manager. - """ - - device_id = 0 - # some validation code - if args: - assert len(args) == 1 and args[0] == 0 - _logger.debug("Set the current env to igpu device queue %s", device_id) - lib.set_curr_env(runtime.get_runtime_ptr(), runtime.get_gpu_device().get_env_ptr()) - device_env = runtime.get_current_device() - yield device_env - - # After yield as the exit method - # TODO : one exit reset the current env to previous value - _logger.debug("Exit method called") - - -@contextmanager -def cpu_context(*args, **kwds): - """A context manager sets the current DeviceEnv inside the global - runtime object to the default CPU DeviceEnv. The CPU DeviceEnv is - yielded by the context manager. - """ - - device_id = 0 - # some validation code - if args: - assert len(args) == 1 and args[0] == 0 - _logger.debug("Set the current env to cpu device queue %s", device_id) - lib.set_curr_env(runtime.get_runtime_ptr(), runtime.get_cpu_device().get_env_ptr()) - device_env = runtime.get_current_device() - yield device_env - - # After yield as the exit method - _logger.debug("Exit method called") diff --git a/dpctl/opencl_core.py b/dpctl/opencl_core.py deleted file mode 100644 index 0c40ef5e49..0000000000 --- a/dpctl/opencl_core.py +++ /dev/null @@ -1,86 +0,0 @@ -##===--------- opencl_core.py - dpctl.ocldrv interface -----*- Python -*---===## -## -## Data paraller Control (dpctl) -## -## Copyright 2020 Intel Corporation -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -##===----------------------------------------------------------------------===## -### -### \file -### This file implements a CFFI interface for dppl_opencl_interface.h -### functions. -##===----------------------------------------------------------------------===## - -import os - -from cffi import FFI - - -ffi = FFI() - -dppl_opencl_interface_incldir = os.environ.get("DPPL_OPENCL_INTERFACE_INCLDIR", None) -dppl_opencl_interface_libdir = os.environ.get("DPPL_OPENCL_INTERFACE_LIBDIR", None) -opencl_libdir = os.environ.get("OpenCL_LIBDIR", None) - -if opencl_libdir is None: - raise ValueError("Abort! Set the OpenCL_LIBDIR envar to point to " "an OpenCL ICD") - -if dppl_opencl_interface_libdir is None: - raise ValueError( - "Abort! Set the DPPL_OPENCL_INTERFACE_LIBDIR envar to " - "point to ibdplibdpglueglue.so" - ) - -if dppl_opencl_interface_incldir is None: - raise ValueError( - "Abort! Set the DP_GLUE_INCLDIR envar to point to " "dppl_opencl_interface.h" - ) - -glue_h = "".join( - list( - filter( - lambda x: len(x) > 0 and x[0] != "#", - open( - dppl_opencl_interface_incldir + "/dppl_opencl_interface.h", "r" - ).readlines(), - ) - ) -).replace("DPPL_API", "") - -# cdef() expects a single string declaring the C types, functions and -# globals needed to use the shared object. It must be in valid C syntax. -ffi.cdef(glue_h) - -ffi_lib_name = "dpctl._opencl_core" - -import sys - -IS_WIN = sys.platform in ["win32", "cygwin"] -del sys - -ffi.set_source( - ffi_lib_name, - """ - #include "dppl_opencl_interface.h" // the C header of the library - """, - include_dirs=[dppl_opencl_interface_incldir], - library_dirs=[dppl_opencl_interface_libdir, opencl_libdir], - extra_link_args=[] if IS_WIN else ["-Wl,-rpath=$ORIGIN"], - libraries=["DPPLOpenCLInterface", "OpenCL"], -) # library name, for the linker -del IS_WIN - -if __name__ == "__main__": - ffi.compile(verbose=True) diff --git a/scripts/build_for_develop.sh b/scripts/build_for_develop.sh index 3d54402846..5144312eee 100755 --- a/scripts/build_for_develop.sh +++ b/scripts/build_for_develop.sh @@ -34,10 +34,6 @@ cp install/lib/*.so dpctl/ mkdir -p dpctl/include cp -r backends/include/* dpctl/include -export DPPL_OPENCL_INTERFACE_LIBDIR=dpctl -export DPPL_OPENCL_INTERFACE_INCLDIR=dpctl/include -# /usr/lib/x86_64-linux-gnu/ -export OpenCL_LIBDIR=${DPCPP_ROOT}/lib export DPPL_SYCL_INTERFACE_LIBDIR=dpctl export DPPL_SYCL_INTERFACE_INCLDIR=dpctl/include diff --git a/setup.py b/setup.py index 4fac02c671..2e2c9eee88 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,6 @@ import numpy as np requirements = [ - "cffi>=1.0.0", "cython", ] @@ -161,7 +160,6 @@ def extensions(): include_package_data=True, ext_modules=extensions(), setup_requires=requirements, - cffi_modules=["./dpctl/opencl_core.py:ffi"], install_requires=requirements, keywords="dpctl", classifiers=[