Skip to content

Header for dpctl sycl interface type casters #960

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 10 commits into from
Nov 5, 2022
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
25 changes: 21 additions & 4 deletions libsyclinterface/helper/source/dpctl_utils_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//===----------------------------------------------------------------------===//

#include "dpctl_utils_helper.h"
#include "Config/dpctl_config.h"
#include <sstream>
#include <string>

Expand All @@ -48,9 +49,11 @@ std::string DPCTL_DeviceTypeToStr(info::device_type devTy)
case info::device_type::custom:
ss << "custom";
break;
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
case info::device_type::host:
ss << "host";
break;
#endif
default:
ss << "unknown";
}
Expand Down Expand Up @@ -90,8 +93,10 @@ backend DPCTL_DPCTLBackendTypeToSyclBackend(DPCTLSyclBackendType BeTy)
switch (BeTy) {
case DPCTLSyclBackendType::DPCTL_CUDA:
return backend::ext_oneapi_cuda;
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
case DPCTLSyclBackendType::DPCTL_HOST:
return backend::host;
#endif
case DPCTLSyclBackendType::DPCTL_LEVEL_ZERO:
return backend::ext_oneapi_level_zero;
case DPCTLSyclBackendType::DPCTL_OPENCL:
Expand All @@ -108,8 +113,10 @@ DPCTLSyclBackendType DPCTL_SyclBackendToDPCTLBackendType(backend B)
switch (B) {
case backend::ext_oneapi_cuda:
return DPCTLSyclBackendType::DPCTL_CUDA;
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
case backend::host:
return DPCTLSyclBackendType::DPCTL_HOST;
#endif
case backend::ext_oneapi_level_zero:
return DPCTLSyclBackendType::DPCTL_LEVEL_ZERO;
case backend::opencl:
Expand Down Expand Up @@ -170,9 +177,11 @@ std::string DPCTL_AspectToStr(aspect aspectTy)
{
std::stringstream ss;
switch (aspectTy) {
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
case aspect::host:
ss << "host";
break;
#endif
case aspect::cpu:
ss << "cpu";
break;
Expand Down Expand Up @@ -242,12 +251,14 @@ std::string DPCTL_AspectToStr(aspect aspectTy)
aspect DPCTL_StrToAspectType(const std::string &aspectTyStr)
{
aspect aspectTy;
if (aspectTyStr == "host") {
aspectTy = aspect::host;
}
else if (aspectTyStr == "cpu") {
if (aspectTyStr == "cpu") {
aspectTy = aspect::cpu;
}
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
else if (aspectTyStr == "host") {
aspectTy = aspect::host;
}
#endif
else if (aspectTyStr == "gpu") {
aspectTy = aspect::gpu;
}
Expand Down Expand Up @@ -312,8 +323,10 @@ aspect DPCTL_StrToAspectType(const std::string &aspectTyStr)
aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy)
{
switch (AspectTy) {
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
case DPCTLSyclAspectType::host:
return aspect::host;
#endif
case DPCTLSyclAspectType::cpu:
return aspect::cpu;
case DPCTLSyclAspectType::gpu:
Expand Down Expand Up @@ -360,8 +373,10 @@ aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy)
DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(aspect Aspect)
{
switch (Aspect) {
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
case aspect::host:
return DPCTLSyclAspectType::host;
#endif
case aspect::cpu:
return DPCTLSyclAspectType::cpu;
case aspect::gpu:
Expand Down Expand Up @@ -487,9 +502,11 @@ std::string DPCTL_GetDeviceFilterString(const device &Device)
case backend::opencl:
ss << "opencl";
break;
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
case backend::host:
ss << "host";
break;
#endif
default:
ss << "unknown";
};
Expand Down
7 changes: 7 additions & 0 deletions libsyclinterface/include/Config/dpctl_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
#cmakedefine DPCTL_ENABLE_L0_PROGRAM_CREATION \
@DPCTL_ENABLE_L0_PROGRAM_CREATION@

/* Version of SYCL DPC++ 2023 compiler at which transition to SYCL 2020 occurs */
#define __SYCL_COMPILER_2023_SWITCHOVER 20221020L

/* Version of SYCL DPC++ compiler at which info::max_work_item_size was
made templated */
#define __SYCL_COMPILER_MAX_WORK_ITEM_SIZE_THRESHOLD 20220805L

/* The DPCPP version used to build dpctl */
#define DPCTL_DPCPP_VERSION "@IntelSycl_VERSION@"

Expand Down
55 changes: 0 additions & 55 deletions libsyclinterface/include/Support/CBindingWrapping.h

This file was deleted.

167 changes: 167 additions & 0 deletions libsyclinterface/include/dpctl_device_selection.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
//===-- dpctl_device_selection.h - Device selector class declar. --*-C++-*- =//
//
//
// Data Parallel Control (dpctl)
//
// Copyright 2020-2022 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 declares classes for device selection.
///
//===----------------------------------------------------------------------===//

#pragma once

#include "Config/dpctl_config.h"
#include "Support/DllExport.h"
#include <CL/sycl.hpp>

namespace dpctl
{
namespace syclinterface
{

#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER

class DPCTL_API dpctl_device_selector
{
public:
virtual ~dpctl_device_selector() = default;
static constexpr int REJECT_DEVICE = -1;
virtual int operator()(const sycl::device &) const;
};

class DPCTL_API dpctl_accelerator_selector : public dpctl_device_selector
{
public:
dpctl_accelerator_selector() = default;
int operator()(const sycl::device &d) const override;
};

class DPCTL_API dpctl_default_selector : public dpctl_device_selector
{
public:
dpctl_default_selector() = default;
int operator()(const sycl::device &d) const override;
};

class DPCTL_API dpctl_gpu_selector : public dpctl_device_selector
{
public:
dpctl_gpu_selector() = default;
int operator()(const sycl::device &d) const override;
};

class DPCTL_API dpctl_cpu_selector : public dpctl_device_selector
{
public:
dpctl_cpu_selector() = default;
int operator()(const sycl::device &d) const override;
};

class DPCTL_API dpctl_filter_selector : public dpctl_device_selector
{
public:
dpctl_filter_selector(const std::string &fs) : _impl(fs) {}
int operator()(const sycl::device &d) const override;

private:
sycl::ext::oneapi::filter_selector _impl;
};

class DPCTL_API dpctl_host_selector : public dpctl_device_selector
{
public:
dpctl_host_selector() = default;
int operator()(const sycl::device &) const override;
};

#else

class DPCTL_API dpctl_device_selector : public sycl::device_selector
{
public:
virtual ~dpctl_device_selector() = default;

virtual int operator()(const sycl::device &device) const = 0;
};

class DPCTL_API dpctl_accelerator_selector : public dpctl_device_selector
{
public:
dpctl_accelerator_selector() : _impl(){};
int operator()(const sycl::device &d) const override;

private:
sycl::accelerator_selector _impl;
};

class DPCTL_API dpctl_default_selector : public dpctl_device_selector
{
public:
dpctl_default_selector() : _impl(){};
int operator()(const sycl::device &d) const override;

private:
sycl::default_selector _impl;
};

class DPCTL_API dpctl_gpu_selector : public dpctl_device_selector
{
public:
dpctl_gpu_selector() : _impl(){};
int operator()(const sycl::device &d) const override;

private:
sycl::gpu_selector _impl;
};

class DPCTL_API dpctl_cpu_selector : public dpctl_device_selector
{
public:
dpctl_cpu_selector() : _impl(){};
int operator()(const sycl::device &d) const override;

private:
sycl::cpu_selector _impl;
};

class DPCTL_API dpctl_filter_selector : public dpctl_device_selector
{
public:
dpctl_filter_selector(const std::string &fs) : _impl(fs) {}

int operator()(const sycl::device &d) const override;

private:
sycl::ext::oneapi::filter_selector _impl;
};

class DPCTL_API dpctl_host_selector : public dpctl_device_selector
{
public:
dpctl_host_selector() : _impl(){};
int operator()(const sycl::device &d) const override;

private:
sycl::host_selector _impl;
};

#endif

} // namespace syclinterface
} // namespace dpctl
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,31 @@ DPCTL_API
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLCPUSelector_Create(void);

/*!
* @brief Returns an opaque wrapper for sycl::ONEAPI::filter_selector object
* based on the passed in filter string.
* @brief Returns an opaque wrapper for sycl::ext::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.
* create a device selector.
* @return An opaque pointer to a sycl::ext::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.
* @brief Returns an opaque wrapper for dpctl_gpu_selector object.
*
* @return An opaque pointer to a sycl::gpu_selector object.
* @return An opaque pointer to a dpctl_gpu_selector object.
* @ingroup DeviceSelectors
*/
DPCTL_API
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLGPUSelector_Create(void);

/*!
* @brief Returns an opaque wrapper for sycl::host_selector object.
* @brief Returns an opaque wrapper for dpctl_host_selector object.
*
* @return An opaque pointer to a sycl::host_selector object.
* @return An opaque pointer to a dpctl_host_selector object.
* @ingroup DeviceSelectors
*/
DPCTL_API
Expand Down
5 changes: 3 additions & 2 deletions libsyclinterface/include/dpctl_sycl_platform_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ __dpctl_give DPCTLSyclPlatformRef DPCTLPlatform_Create(void);

/*!
* @brief Creates a new DPCTLSyclPlatformRef for a SYCL platform constructed
* using the device_selector wrapped by DPCTLSyclDeviceSelectorRef.
* using the dpctl_device_selector wrapped by DPCTLSyclDeviceSelectorRef.
*
* @param DSRef An opaque pointer to a SYCL device_selector object.
* @param DSRef An opaque pointer to a SYCL dpctl_device_selector
* object.
* @return A new DPCTLSyclPlatformRef pointer wrapping a SYCL platform object.
* @ingroup PlatformInterface
*/
Expand Down
Loading