Skip to content

Support filter selector #271

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 54 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
312a340
Minor CMake modifications to compile all files.
Feb 14, 2021
d611864
Device selector support
Feb 15, 2021
c5c1f37
Expose SYCL's device selector classes to Python API.
Feb 15, 2021
e4e3ac0
Add declarations to pxd file.
Feb 16, 2021
6b972b9
Enables creation of a SyclDevice from a filter string
Feb 16, 2021
c34c349
Handle exceptions in C API and Python test cases.
Feb 17, 2021
583b821
Add docstrings.
Feb 17, 2021
2f67b7e
Change the way tests are recorded by pytest.
Feb 17, 2021
1bcdda4
Black formatting.
Feb 17, 2021
87d6d5b
Skip instead of fail when device not found.
Feb 18, 2021
d6626e6
Fixes to ensure we do not expose _SyclDevice to users.
Feb 18, 2021
c08c007
Fix compilation error.
Feb 18, 2021
adf2be6
Fix compilation error properly this time.
Feb 19, 2021
72cb92c
Do not use host or 0 for invalid filter test cases. These can be vali…
Feb 19, 2021
28022af
Update changelog.
Feb 19, 2021
f799f55
WIP macros to generate vector types and functions.
Feb 19, 2021
62ef330
Introduces a device manager module.
Feb 18, 2021
7a01dc9
Fix few doc strings and rename a function.
Feb 19, 2021
e8a5068
Clang-format changes...
Feb 19, 2021
6e10e00
Merge branch 'upstream_master' into feature/device_manager
Feb 20, 2021
1d7649c
Remove duplicate declaration.
Feb 20, 2021
2360ec3
Enables creation of a SyclDevice from a filter string
Feb 16, 2021
b123214
Handle exceptions in C API and Python test cases.
Feb 17, 2021
4a7bd6e
Add docstrings.
Feb 17, 2021
b5272a7
Initial set of refactoring to now support filter selectors in C API.
Feb 5, 2021
9b6d390
Add a DPCTLSyclQueue_Create function.
Feb 10, 2021
d8991c0
Reformat using clang-format.
Feb 10, 2021
ee20bcd
Changes the implementation of the queue manager.
Feb 12, 2021
ae3874a
Split out the device management functions into separate source file.
Feb 12, 2021
f586a23
Split program API into interface and manager and rename to module.
Feb 12, 2021
94750c6
Fix device manager.
Feb 14, 2021
4fde347
Rename platform_interface to platform_manager and remove old functions.
Feb 14, 2021
323b048
Move the opaque vector types to dpctl_sycl_types.h
Feb 14, 2021
a07edbb
Add context constructor C API calls.
Feb 14, 2021
f0440fd
Fix formatting
Feb 14, 2021
c9c5115
Fix device selector test case.
Feb 16, 2021
97c14e4
Minor rearrangement of functions to reduce diff noise.
Feb 17, 2021
80d039e
Documentation changes.
Feb 17, 2021
71c48c0
Minor cosmetic edits.
Feb 20, 2021
e560c8c
Work in progress macros.
Feb 22, 2021
547cc84
Merge branch 'feature/dpctl_vector_macros' into feature/device_manager
Feb 22, 2021
1058f31
rename list macros to vector macros.
Feb 22, 2021
d9a43f0
Use macros to generate vectors.
Feb 23, 2021
04b79ae
Doc string updates and changes _GetAt function.
Feb 23, 2021
2c07a6d
Change how vectros are deleted.
Feb 23, 2021
a6fd1d6
Skip devices that have negative score.
Feb 23, 2021
048de90
Add a new device manager module.
Feb 23, 2021
3ac951a
ignore generated coverage reports.
Feb 23, 2021
7174241
wip get_devices()
Feb 24, 2021
0ef9419
Fixes get_devices.
Feb 24, 2021
aaf54f5
Final set of changes to device manager.
Feb 25, 2021
db92aee
Add empty line.
Feb 25, 2021
1bbd797
Improve device_factory test case.
Feb 25, 2021
669a47d
Merge branch 'feature/device_manager' into support_filter_selector
Feb 25, 2021
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ target/

# generated Cython files
_dpctl_bindings*

# generated C API coverage reports
dpctl-c-api-coverage
7 changes: 7 additions & 0 deletions dpctl-capi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ endif()
file(GLOB_RECURSE sources
${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp
)

# Exclude from sources
list(REMOVE_ITEM
sources
"${CMAKE_CURRENT_SOURCE_DIR}/source/dpctl_vector_templ.cpp"
)

file(GLOB_RECURSE helper_sources
${CMAKE_CURRENT_SOURCE_DIR}/helper/source/*.cpp
)
Expand Down
42 changes: 42 additions & 0 deletions dpctl-capi/helper/include/dpctl_async_error_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===-- dpctl_async_error_handler.h - An async error handler -*-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
/// A functor to use for passing an error handler callback function to sycl
/// context and queue contructors.
//===----------------------------------------------------------------------===//

#pragma once

#include "dpctl_error_handler_type.h"
#include <CL/sycl.hpp>

class DPCTL_AsycErrorHandler
{
error_handler_callback *handler_ = nullptr;

public:
DPCTL_AsycErrorHandler(error_handler_callback *err_handler)
: handler_(err_handler)
{
}

void operator()(const cl::sycl::exception_list &exceptions);
};
72 changes: 69 additions & 3 deletions dpctl-capi/helper/include/dpctl_utils_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,74 @@

#pragma once

#include "../include/dpctl_sycl_enum_types.h"
#include <CL/sycl.hpp>
using namespace cl::sycl;

std::string DPCTL_DeviceTypeToStr(info::device_type devTy);
info::device_type DPCTL_StrToDeviceType(std::string devTyStr);
/*!
* @brief Converts a sycl::info::device_type input value to a string.
*
* @param devTy A sycl::info::device_type enum value.
* @return A string representation of a sycl::info::device_type enum.
*/
std::string DPCTL_DeviceTypeToStr(sycl::info::device_type devTy);

/*!
* @brief Converts a string to sycl::info::device_type enum value.
*
* Tries to interpret the input string a return a corresponding device_type. If
* no conversion is possible, then a runtime_error is thrown.
*
* @param devTyStr Input string for which we search a
* sycl::info::device_type enum value.
* @return The sycl::info::device_type enum value corresponding to the input
* string.
* @throws runtime_error
*/
sycl::info::device_type DPCTL_StrToDeviceType(const std::string &devTyStr);

/*!
* @brief Converts a DPCTLSyclBackendType enum value to its corresponding
* sycl::backend enum value. If conversion fails, a runtime_error is thrown.
*
* @param BeTy My Param doc
* @return A sycl::backend enum value for the input
* DPCTLSyclDeviceType enum value.
* @throws runtime_error
*/
sycl::backend DPCTL_DPCTLBackendTypeToSyclBackend(DPCTLSyclBackendType BeTy);

/*!
* @brief Converts a sycl::backend enum value to corresponding
* DPCTLSyclBackendType enum value.
*
* @param B sycl::backend to be converted to
* DPCTLSyclBackendType enum.
* @return A DPCTLSyclBackendType enum value for the input
* sycl::backend enum value.
*/
DPCTLSyclBackendType DPCTL_SyclBackendToDPCTLBackendType(sycl::backend B);

/*!
* @brief Converts a DPCTLSyclDeviceType enum value to its corresponding
* sycl::info::device_type enum value. If conversion fails, a runtime_error is
* thrown.
*
* @param DTy A DPCTLSyclDeviceType enum value
* @return A sycl::info::device_type enum value for the input
* DPCTLSyclDeviceType enum value.
* @throws runtime_error
*/
sycl::info::device_type
DPCTL_DPCTLDeviceTypeToSyclDeviceType(DPCTLSyclDeviceType DTy);

/*!
* @brief Converts a sycl::info::device_type enum value to corresponding
* DPCTLSyclDeviceType enum value.
*
* @param D sycl::info::device_type to be converted to
* DPCTLSyclDeviceType enum.
* @return A DPCTLSyclDeviceType enum value for the input
* sycl::info::device_type enum value.
*/
DPCTLSyclDeviceType
DPCTL_SyclDeviceTypeToDPCTLDeviceType(sycl::info::device_type D);
33 changes: 33 additions & 0 deletions dpctl-capi/helper/include/dpctl_vector_macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//=== dpctl_vector_macros.h - Macros to help build function sig. -*-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 These macros are used in dpctl_vector_templ.cpp. They help build the
/// function signatures for the functions defined in dpctl_vector_templ.cpp.
///
//===----------------------------------------------------------------------===//

#pragma once

#define xFN(TYPE, NAME) DPCTL##TYPE##Vector##_##NAME
#define FN(TYPE, NAME) xFN(TYPE, NAME)
#define xVECTOR(EL) DPCTL##EL##VectorRef
#define VECTOR(EL) xVECTOR(EL)
#define xSYCLREF(EL) DPCTLSycl##EL##Ref
#define SYCLREF(EL) xSYCLREF(EL)
42 changes: 42 additions & 0 deletions dpctl-capi/helper/source/dpctl_async_error_handler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===-- dpctl_async_error_handler.h - An async error handler -*-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
/// A functor to use for passing an error handler callback function to sycl
/// context and queue contructors.
//===----------------------------------------------------------------------===//

#include "dpctl_async_error_handler.h"

void DPCTL_AsycErrorHandler::operator()(
const cl::sycl::exception_list &exceptions)
{
for (std::exception_ptr const &e : exceptions) {
try {
std::rethrow_exception(e);
} catch (cl::sycl::exception const &e) {
std::cerr << "Caught asynchronous SYCL exception:\n"
<< e.what() << std::endl;
// FIXME: Change get_cl_code() to code() once DPCPP supports it.
auto err_code = e.get_cl_code();
handler_(err_code);
}
}
}
78 changes: 77 additions & 1 deletion dpctl-capi/helper/source/dpctl_utils_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ std::string DPCTL_DeviceTypeToStr(info::device_type devTy)
/*!
* Transforms string to enum info::device_type.
*/
info::device_type DPCTL_StrToDeviceType(std::string devTyStr)
info::device_type DPCTL_StrToDeviceType(const std::string &devTyStr)
{
info::device_type devTy;
if (devTyStr == "cpu") {
Expand All @@ -84,3 +84,79 @@ info::device_type DPCTL_StrToDeviceType(std::string devTyStr)
}
return devTy;
}

backend DPCTL_DPCTLBackendTypeToSyclBackend(DPCTLSyclBackendType BeTy)
{
switch (BeTy) {
case DPCTLSyclBackendType::DPCTL_CUDA:
return backend::cuda;
case DPCTLSyclBackendType::DPCTL_HOST:
return backend::host;
case DPCTLSyclBackendType::DPCTL_LEVEL_ZERO:
return backend::level_zero;
case DPCTLSyclBackendType::DPCTL_OPENCL:
return backend::opencl;
default:
throw runtime_error("Unsupported backend type", -1);
}
}

DPCTLSyclBackendType DPCTL_SyclBackendToDPCTLBackendType(backend B)
{
switch (B) {
case backend::cuda:
return DPCTLSyclBackendType::DPCTL_CUDA;
case backend::host:
return DPCTLSyclBackendType::DPCTL_HOST;
case backend::level_zero:
return DPCTLSyclBackendType::DPCTL_LEVEL_ZERO;
case backend::opencl:
return DPCTLSyclBackendType::DPCTL_OPENCL;
default:
return DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
}
}

info::device_type DPCTL_DPCTLDeviceTypeToSyclDeviceType(DPCTLSyclDeviceType DTy)
{
switch (DTy) {
case DPCTLSyclDeviceType::DPCTL_ACCELERATOR:
return info::device_type::accelerator;
case DPCTLSyclDeviceType::DPCTL_ALL:
return info::device_type::all;
case DPCTLSyclDeviceType::DPCTL_AUTOMATIC:
return info::device_type::automatic;
case DPCTLSyclDeviceType::DPCTL_CPU:
return info::device_type::cpu;
case DPCTLSyclDeviceType::DPCTL_CUSTOM:
return info::device_type::custom;
case DPCTLSyclDeviceType::DPCTL_GPU:
return info::device_type::gpu;
case DPCTLSyclDeviceType::DPCTL_HOST_DEVICE:
return info::device_type::host;
default:
throw runtime_error("Unsupported device type", -1);
}
}

DPCTLSyclDeviceType DPCTL_SyclDeviceTypeToDPCTLDeviceType(info::device_type D)
{
switch (D) {
case info::device_type::accelerator:
return DPCTLSyclDeviceType::DPCTL_ACCELERATOR;
case info::device_type::all:
return DPCTLSyclDeviceType::DPCTL_ALL;
case info::device_type::automatic:
return DPCTLSyclDeviceType::DPCTL_AUTOMATIC;
case info::device_type::cpu:
return DPCTLSyclDeviceType::DPCTL_CPU;
case info::device_type::custom:
return DPCTLSyclDeviceType::DPCTL_CUSTOM;
case info::device_type::gpu:
return DPCTLSyclDeviceType::DPCTL_GPU;
case info::device_type::host:
return DPCTLSyclDeviceType::DPCTL_HOST_DEVICE;
default:
return DPCTLSyclDeviceType::DPCTL_UNKNOWN_DEVICE;
}
}
34 changes: 34 additions & 0 deletions dpctl-capi/include/dpctl_error_handler_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===--- dpctl_error_handler_types.h - Error handler callbacks -*-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
/// Defines types for callback functions to use for error handling in dpctl.
///
//===----------------------------------------------------------------------===//

#pragma once

/*!
* @brief
*
* @param err_code My Param doc
* @return {return} My Param doc
*/
typedef void error_handler_callback(int err_code);
31 changes: 30 additions & 1 deletion dpctl-capi/include/dpctl_sycl_context_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,42 @@
#include "Support/DllExport.h"
#include "Support/ExternC.h"
#include "Support/MemOwnershipAttrs.h"
#include "dpctl_async_error_handler.h"
#include "dpctl_data_types.h"
#include "dpctl_sycl_platform_interface.h"
#include "dpctl_sycl_enum_types.h"
#include "dpctl_sycl_types.h"
#include <stdbool.h>

DPCTL_C_EXTERN_C_BEGIN

/*!
* @brief
*
* @param DRef My Param doc
* @param error_handler My Param doc
* @param properties My Param doc
* @return {return} My Param doc
*/
DPCTL_API
__dpctl_give DPCTLSyclContextRef
DPCTLContext_Create(__dpctl_keep const DPCTLSyclDeviceRef DRef,
error_handler_callback *error_handler,
int properties);

/*!
* @brief
*
* @param DVRef My Param doc
* @param error_handler My Param doc
* @param properties My Param doc
* @return {return} My Param doc
*/
DPCTL_API
__dpctl_give DPCTLSyclContextRef DPCTLContext_CreateFromDeviceVector(
__dpctl_keep const DPCTLDeviceVectorRef DVRef,
error_handler_callback *error_handler,
int properties);

/*!
* @brief Checks if two DPCTLSyclContextRef objects point to the same
* sycl::context.
Expand Down
Loading