Skip to content

Dppl program interface #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
defc264
Move _memory.pyx
PokhodenkoSA Sep 15, 2020
8b811c5
Import setuptools before Cython. Otherwise, both might disagree about…
PokhodenkoSA Sep 15, 2020
0704258
Add dppl._memory Cython module.
PokhodenkoSA Sep 15, 2020
e57927d
Run dppl/tests/dppl_tests too when run all unit tests.
PokhodenkoSA Sep 15, 2020
267492f
Add tests for memory manager.
PokhodenkoSA Sep 15, 2020
5ff3eb0
Split tests for memory. One test one context (no, CPU, GPU).
PokhodenkoSA Sep 15, 2020
902bc8a
[opt] Rename getpyexts() to extensions().
PokhodenkoSA Sep 15, 2020
5d81879
Adds C and Cython API for portions of Sycl queue, device, context int…
diptorupd Sep 15, 2020
758aacc
Add C-API stub library for sycl memory.
PokhodenkoSA Sep 16, 2020
35a4674
Add missing DPPL_API.
diptorupd Sep 16, 2020
7bb5faf
Move platform specific functions into a separate file.
diptorupd Sep 16, 2020
4a11490
Create a single utility function to delete C strings.
diptorupd Sep 16, 2020
456bdf2
Change the wrap/unwrap functions to also include the type.
diptorupd Sep 17, 2020
dd8d846
Add an interoperability function to create Sycl kernels from SPIR-V.
diptorupd Sep 17, 2020
6e246fb
Update backends/source/dppl_utils.cpp
PokhodenkoSA Sep 17, 2020
97b53ca
Merge branch 'pr/30' into feature/usm
PokhodenkoSA Sep 17, 2020
abcf6f3
Add _sycl_core.pxd file.
PokhodenkoSA Sep 17, 2020
039b794
Remove using of PyCapsule in _memory.pyx.
PokhodenkoSA Sep 17, 2020
dc72b03
Small style fixes in _memory.pyx.
PokhodenkoSA Sep 17, 2020
b5ab5d6
Moved functions from _memory.pyx to C-API interface library.
PokhodenkoSA Sep 17, 2020
c57c05c
Move Cython definitions for backend to single pxd file.
PokhodenkoSA Sep 17, 2020
c075f0c
Remove SyclQueue from _memory.pyx
PokhodenkoSA Sep 17, 2020
708fd1f
Use SyclQueue from
PokhodenkoSA Sep 17, 2020
5d3db20
Remove cl::sycl::queue from _memory.pyx
PokhodenkoSA Sep 17, 2020
6747080
Removed commented code from _memory.pyx
PokhodenkoSA Sep 17, 2020
56241ef
Eliminate temporary context object.
PokhodenkoSA Sep 17, 2020
7fabbe4
Fix style.
PokhodenkoSA Sep 17, 2020
7899c07
Add a kernel submission interface.
diptorupd Sep 18, 2020
abd373b
Add MemoryUSM* classes.
PokhodenkoSA Sep 18, 2020
ba3e497
Add __getbuffer__ to Shared and Host MemoryUSM classes.
PokhodenkoSA Sep 18, 2020
00d63b0
Rename C-API types for USM.
PokhodenkoSA Sep 18, 2020
28f0496
Add DPPLUSM_GetPointerType and remove types from CL/sycl.hpp from _me…
PokhodenkoSA Sep 18, 2020
80cec2a
Clean unused code from _memory_.pyx
PokhodenkoSA Sep 18, 2020
bc68d17
Add a change to ChameLists.txt to localte the libDPPLSyclInterface wh…
diptorupd Sep 18, 2020
debc2eb
Merge branch 'master' into feature/usm
PokhodenkoSA Sep 18, 2020
8ef95df
Small fixes.
PokhodenkoSA Sep 18, 2020
fa585da
Remove unused code.
PokhodenkoSA Sep 18, 2020
533e74b
Fix style.
PokhodenkoSA Sep 18, 2020
ab7a9ba
Fix style
PokhodenkoSA Sep 18, 2020
b73fbdd
Change the wrap/unwrap functions to also include the type.
diptorupd Sep 17, 2020
c9a0a75
Add an interoperability function to create Sycl kernels from SPIR-V.
diptorupd Sep 17, 2020
29b5ae6
Add a kernel submission interface.
diptorupd Sep 18, 2020
6b5209b
Add a change to ChameLists.txt to localte the libDPPLSyclInterface wh…
diptorupd Sep 18, 2020
2959a98
Merge branch 'dppl_program_interface' of github.com:diptorupd/pydppl …
diptorupd Sep 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backends/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ add_library(
SHARED
source/dppl_sycl_context_interface.cpp
source/dppl_sycl_device_interface.cpp
source/dppl_sycl_kernel_interface.cpp
source/dppl_sycl_platform_interface.cpp
source/dppl_sycl_queue_interface.cpp
source/dppl_sycl_queue_manager.cpp
source/dppl_sycl_usm_interface.cpp
source/dppl_utils.cpp
)

Expand Down
4 changes: 2 additions & 2 deletions backends/include/Support/CBindingWrapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
#pragma once

#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
inline ty *unwrap(ref P) { \
inline ty *unwrap_##ty(ref P) { \
return reinterpret_cast<ty*>(P); \
} \
\
inline ref wrap(const ty *P) { \
inline ref wrap_##ty(const ty *P) { \
return reinterpret_cast<ref>(const_cast<ty*>(P)); \
}

Expand Down
219 changes: 219 additions & 0 deletions backends/include/dppl_sycl_kernel_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
//===---- dppl_sycl_kernel_interface.h - DPPL-SYCL interface --*--C++ --*--===//
//
// Python Data Parallel Processing Library (PyDPPL)
//
// 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 header declares a C API to create Sycl kernels from OpenCL kernels. In
/// future, API to create interoperability kernels from other languages such as
/// Level-0 driver API may be added here.
///
/// \todo Investigate what we should do when we add support for Level-0 API.
///
//===----------------------------------------------------------------------===//

#pragma once

#include "dppl_data_types.h"
#include "dppl_sycl_types.h"
#include "Support/DllExport.h"
#include "Support/ExternC.h"
#include "Support/MemOwnershipAttrs.h"

DPPL_C_EXTERN_C_BEGIN

/*!
* @brief Enum of currently support types for kernel arguments.
*
* \todo Add support for sycl::buffer
*
*/
enum DPPLArgTypes
{
CHAR,
SIGNED_CHAR,
UNSIGNED_CHAR,
SHORT,
INT,
UNSIGNED_INT,
LONG,
UNSIGNED_LONG,
LONG_LONG,
UNSIGNED_LONG_LONG,
SIZE_T,
FLOAT,
DOUBLE,
LONG_DOUBLE,
CHAR_P,
SIGNED_CHAR_P,
UNSIGNED_CHAR_P,
SHORT_P,
INT_P,
UNSIGNED_INT_P,
LONG_P,
UNSIGNED_LONG_P,
LONG_LONG_P,
UNSIGNED_LONG_LONG_P,
SIZE_T_P,
FLOAT_P,
DOUBLE_P,
LONG_DOUBLE_P
};

/*!
* @brief A union representing an OpenCL kernel argument that is either a basic
* C type of a pointer of the type.
*
*/
union DPPLArgValue
{
char char_arg;
signed char schar_arg;
unsigned char uchar_arg;
short short_arg;
int int_arg;
unsigned int uint_arg;
long long_arg;
unsigned long ulong_arg;
long long longlong_arg;
unsigned long long ulonglong_arg;
size_t size_t_arg;
float float_arg;
double double_arg;
long double longdouble_arg;
char *char_p_arg;
signed char *schar_p_arg;
unsigned char *uchar_p_arg;
short *short_p_arg;
int *int_p_arg;
unsigned int *uint_p_arg;
long *long_p_arg;
unsigned long *ulong_p_arg;
long long *longlong_p_arg;
unsigned long long *ulonglong_p_arg;
size_t *size_t_p_arg;
float *float_p_arg;
double *double_p_arg;
long double *longdouble_p_arg;
};

/*!
* @brief The tagged union is used to pass through OpenCL kernel arguments to
* Sycl.
*
*/
struct DPPLKernelArg
{
enum DPPLArgTypes argType;
union DPPLArgValue argVal;
};

/*!
* @brief Create a Sycl Kernel from an OpenCL SPIR-V binary
*
* Sycl 1.2 does expose any method to create a sycl::program from a SPIR-V IL
* file. To get around this limitation, we need to use the Sycl feature to
* create an interoperability kernel from an OpenCL kernel. This function first
* creates an OpenCL program and kernel from the SPIR-V binary and then using
* the Sycl-OpenCL interoperability feature creates a Sycl kernel from the
* OpenCL kernel.
*
* The feature to create a Sycl kernel from a SPIR-V IL binary will be available
* in Sycl 2.0.
*
* @param Ctx An opaque pointer to a sycl::context
* @param IL SPIR-V binary
* @return A new SyclProgramRef pointer if the program creation succeeded,
* else returns NULL.
*/
DPPL_API
__dppl_give DPPLSyclKernelRef
DPPLKernel_CreateKernelFromSpirv (__dppl_keep const DPPLSyclContextRef Ctx,
__dppl_keep const void *IL,
size_t length,
const char *KernelName = nullptr);

/*!
* @brief Returns a C string for the kernel name.
*
* @param KRef DPPLSyclKernelRef pointer to an OpenCL
* interoperability kernel.
* @return If a kernel name exists then returns it as a C string, else
* returns a nullptr.
*/
DPPL_API
__dppl_give const char*
DPPLKernel_GetFunctionName (__dppl_keep const DPPLSyclKernelRef KRef);

/*!
* @brief Returns the number of arguments for the OpenCL kernel.
*
* @param KRef DPPLSyclKernelRef pointer to an OpenCL
* interoperability kernel.
* @return Returns the number of arguments for the OpenCL interoperability
* kernel.
*/
DPPL_API
size_t
DPPLKernel_GetNumArgs (__dppl_keep const DPPLSyclKernelRef KRef);

/*!
* @brief Deletes the DPPLSyclKernelRef after casting it to a sycl::kernel.
*
* @param KRef DPPLSyclKernelRef pointer to an OpenCL
* interoperability kernel.
*/
DPPL_API
void
DPPLKernel_DeleteKernelRef (__dppl_take DPPLSyclKernelRef KRef);


/*!
* @brief Submits the kernel to the specified queue using give arguments.
*
* A wrapper over sycl::queue.submit(). The function takes an OpenCL
* interoperability kernel, the kernel arguments, and a sycl queue as input
* arguments. The kernel arguments are passed in as an array of the
* DPPLKernelArg tagged union.
*
* \todo sycl::buffer arguments are not supported yet.
*
* @param KRef Opaque pointer to a OpenCL interoperability kernel
* wrapped inside a sycl::kernel.
* @param QRef Opaque pointer to the sycl::queue where the kernel
* will be enqueued.
* @param Args An array of the DPPLKernelArg tagged union type that
* represents the kernel arguments for the kernel.
* @param NArgs The number of kernel arguments (size of Args array).
* @param Range Array storing the range dimensions that can have a
* maximum size of three. Note the number of values
* in the array depends on the number of dimensions.
* @param NDims Number of dimensions in the range (size of Range).
* @return A opaque pointer to the sycl::event returned by the
* sycl::queue.submit() function.
*/
DPPL_API
DPPLSyclEventRef
DPPLKernel_Submit (__dppl_keep DPPLSyclKernelRef KRef,
__dppl_keep DPPLSyclQueueRef QRef,
__dppl_keep DPPLKernelArg *Args,
size_t NArgs,
size_t Range[3],
size_t NDims);

DPPL_C_EXTERN_C_END
40 changes: 33 additions & 7 deletions backends/include/dppl_sycl_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,65 @@
//===----------------------------------------------------------------------===//
///
/// \file
/// This file defines types used by DPPL's C interface to SYCL.
/// This file defines opaque pointer types wrapping Sycl object that get used
/// by DPPL's C API.
///
//===----------------------------------------------------------------------===//

#pragma once

/*!
* @brief
* @brief Opaque pointer used to represent references to sycl::context*
*
* @see sycl::context
*/
typedef struct DPPLOpaqueSyclContext *DPPLSyclContextRef;

/*!
* @brief
* @brief Opaque pointer used to represent references to sycl::device*
*
* @see sycl::device
*/
typedef struct DPPLOpaqueSyclDevice *DPPLSyclDeviceRef;

/*!
* @brief
* @brief Opaque pointer used to represent references to sycl::event*
*
* @see sycl::event
*/
typedef struct DPPLOpaqueSyclEvent *DPPLSyclEventRef;

/*!
* @brief Opaque pointer used to represent references to sycl::kernel*
*
* @see sycl::kernel
*/
typedef struct DPPLOpaqueSyclProgram *DPPLSyclKernelRef;

/*!
* @brief Opaque pointer used to represent references to sycl::platform*
*
* @see sycl::platform
*/
typedef struct DPPLOpaqueSyclPlatform *DPPLSyclPlatformRef;

/*!
* @brief Opaque pointer used to represent references to sycl::program*
*
* @see sycl::program
*/
typedef struct DPPLOpaqueSyclProgram *DPPLSyclProgramRef;

/*!
* @brief Used to pass a sycl::queue opaquely through DPPL interfaces.
* @brief Opaque pointer used to represent references to sycl::queue*
*
* @see sycl::queue
*/
typedef struct DPPLOpaqueSyclQueue *DPPLSyclQueueRef;

/*!
* @brief Used to pass a sycl::program opaquely through DPPL interfaces.
* @brief Used to pass a sycl::usm memory opaquely through DPPL interfaces.
*
* @see sycl::usm
*/
typedef struct DPPLOpaqueSyclProgram *DPPLSyclProgramRef;
typedef struct DPPLOpaqueSyclUSM *DPPLSyclUSMRef;
Loading