Skip to content

Feature/device selectors #274

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

Merged
merged 15 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Documentation improvements
- Cmake improvements and Coverage for C API, Cython and Python
- Add support for Level Zero
- Added support for Level Zero devices and queues
- Added support for SYCL standard device_selector classes
- SyclDevice instances can now be constructed using filter selector strings
- Code of conduct

### Fixed
Expand Down
1 change: 1 addition & 0 deletions docs/dpCtl_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Classes

.. autoclass:: dpctl.SyclDevice
:members:
:inherited-members:
:undoc-members:

.. autoclass:: dpctl.SyclEvent
Expand Down
26 changes: 12 additions & 14 deletions dpctl-capi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,17 @@ else()
message(FATAL_ERROR "Unsupported system.")
endif()

add_library(
DPCTLSyclInterface
SHARED
source/dpctl_sycl_context_interface.cpp
source/dpctl_sycl_device_interface.cpp
source/dpctl_sycl_event_interface.cpp
source/dpctl_sycl_kernel_interface.cpp
source/dpctl_sycl_platform_interface.cpp
source/dpctl_sycl_program_interface.cpp
source/dpctl_sycl_queue_interface.cpp
source/dpctl_sycl_queue_manager.cpp
source/dpctl_sycl_usm_interface.cpp
source/dpctl_utils.cpp
helper/source/dpctl_utils_helper.cpp
file(GLOB_RECURSE sources
${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp
)
file(GLOB_RECURSE helper_sources
${CMAKE_CURRENT_SOURCE_DIR}/helper/source/*.cpp
)

add_library(DPCTLSyclInterface
SHARED
${sources}
${helper_sources}
)

target_include_directories(DPCTLSyclInterface
Expand All @@ -83,6 +80,7 @@ target_include_directories(DPCTLSyclInterface
${CMAKE_SOURCE_DIR}/helper/include/
${DPCPP_SYCL_INCLUDE_DIR}
)

target_link_libraries(DPCTLSyclInterface
PRIVATE ${DPCPP_SYCL_LIBRARY}
PRIVATE ${DPCPP_OPENCL_LIBRARY}
Expand Down
33 changes: 33 additions & 0 deletions dpctl-capi/include/dpctl_sycl_device_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,39 @@

DPCTL_C_EXTERN_C_BEGIN

/*!
* @brief Returns a copy of the DPCTLSyclDeviceRef object.
*
* @param DRef DPCTLSyclDeviceRef object to be copied.
* @return A new DPCTLSyclDeviceRef created by copying the passed in
* DPCTLSyclDeviceRef object.
*/
DPCTL_API
__dpctl_give DPCTLSyclDeviceRef
DPCTLDevice_Copy(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Returns a new DPCTLSyclDeviceRef opaque object wrapping a SYCL device
* instance as a host device.
*
* @return An opaque pointer to the host SYCL device.
*/
DPCTL_API
__dpctl_give DPCTLSyclDeviceRef DPCTLDevice_Create();

/*!
* @brief Returns a new DPCTLSyclDeviceRef opaque object created using the
* provided device_selector.
*
* @param DSRef An opaque pointer to a SYCL device_selector.
* @return Returns an opaque pointer to a SYCL device created using the
* device_selector, if the requested device could not be created a
* nullptr is returned.
*/
DPCTL_API
__dpctl_give DPCTLSyclDeviceRef DPCTLDevice_CreateFromSelector(
__dpctl_keep const DPCTLSyclDeviceSelectorRef DSRef);

/*!
* @brief Prints out some of the info::deivice attributes for the device.
*
Expand Down
108 changes: 108 additions & 0 deletions dpctl-capi/include/dpctl_sycl_device_selector_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//=== dpctl_sycl_device_selector_interface.h - device_selector C API -*-C++-*-//
//
// Data Parallel Control (dpCtl)
//
// Copyright 2020-2021 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 C contructors for the various SYCL device_selector
/// classes.
///
//===----------------------------------------------------------------------===//

#pragma once

#include "Support/DllExport.h"
#include "Support/ExternC.h"
#include "Support/MemOwnershipAttrs.h"
#include "dpctl_sycl_types.h"

DPCTL_C_EXTERN_C_BEGIN

/**
* \defgroup DeviceSelectors C API for SYCL Device Selectors
*/

/*!
* @brief Returns an opaque wrapper for sycl::accelerator_selector object.
*
* @return An opaque pointer to a sycl::accelerator_selector object.
* @ingroup DeviceSelectors
*/
DPCTL_API
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLAcceleratorSelector_Create();

/*!
* @brief Returns an opaque wrapper for sycl::default_selector object.
*
* @return An opaque pointer to a sycl::default_selector object.
*/
DPCTL_API
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLDefaultSelector_Create();

/*!
* @brief Returns an opaque wrapper for sycl::cpu_selector object.
*
* @return An opaque pointer to a sycl::cpu_selector object.
* @ingroup DeviceSelectors
*/
DPCTL_API
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLCPUSelector_Create();

/*!
* @brief Returns an opaque wrapper for sycl::ONEAPI::filter_selector object
* based on the passed in filter string.
*
* @param filter_str A C string providing a filter based on which to
* create a device_selector.
* @return An opaque pointer to a sycl::ONEAPI::filter_selector object.
* @ingroup DeviceSelectors
*/
DPCTL_API
__dpctl_give DPCTLSyclDeviceSelectorRef
DPCTLFilterSelector_Create(__dpctl_keep const char *filter_str);

/*!
* @brief Returns an opaque wrapper for sycl::gpu_selector object.
*
* @return An opaque pointer to a sycl::gpu_selector object.
* @ingroup DeviceSelectors
*/
DPCTL_API
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLGPUSelector_Create();

/*!
* @brief Returns an opaque wrapper for sycl::host_selector object.
*
* @return An opaque pointer to a sycl::host_selector object.
* @ingroup DeviceSelectors
*/
DPCTL_API
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLHostSelector_Create();

/*!
* @brief Deletes the DPCTLSyclDeviceSelectorRef after casting it to a
* sycl::device_selector.
*
* @param DSRef An opaque DPCTLSyclDeviceSelectorRef pointer that would be
* freed.
* @ingroup DeviceSelectors
*/
DPCTL_API
void DPCTLDeviceSelector_Delete(__dpctl_take DPCTLSyclDeviceSelectorRef DSRef);

DPCTL_C_EXTERN_C_END
6 changes: 6 additions & 0 deletions dpctl-capi/include/dpctl_sycl_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ typedef struct DPCTLOpaqueSyclContext *DPCTLSyclContextRef;
*/
typedef struct DPCTLOpaqueSyclDevice *DPCTLSyclDeviceRef;

/*!
* @brief Opaque pointer to a sycl::device_selector
*
*/
typedef struct DPCTLOpaqueSyclDeviceSelector *DPCTLSyclDeviceSelectorRef;

/*!
* @brief Opaque pointer to a sycl::event
*
Expand Down
Loading