Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b4a5ffa
[SYCL] Implement new env var SYCL_DEVICE_TRIPLE
bso-intel Aug 1, 2020
0456825
added description of SYCL_DEVICE_TRIPLE in doc
bso-intel Aug 1, 2020
72634d5
disable windows tentatively
bso-intel Aug 1, 2020
6ec2671
clean up format
bso-intel Aug 1, 2020
5471b63
Merge remote-tracking branch 'upstream/sycl' into sycl-device-triple
bso-intel Aug 14, 2020
6b25217
accmmodated feedback
bso-intel Aug 14, 2020
0e9c8d4
added * for a backend type
bso-intel Aug 16, 2020
6304163
Merge remote-tracking branch 'upstream/sycl' into sycl-device-triple
bso-intel Aug 24, 2020
35937b5
changed the order of device triple
bso-intel Aug 25, 2020
8e38292
clang-format
bso-intel Aug 25, 2020
779d304
Update sycl/include/CL/sycl/device_triple.hpp
bso-intel Aug 25, 2020
f8034c3
Update sycl/source/device_triple.cpp
bso-intel Aug 25, 2020
da4eab2
feedback accmmodated
bso-intel Aug 25, 2020
b995852
Merge branch 'sycl-device-triple' of https://github.com/bso-intel/llv…
bso-intel Aug 25, 2020
fa1fd6e
clang-format
bso-intel Aug 25, 2020
230bbd4
moved device_triple.hpp/cpp into 'detail' namespace
bso-intel Aug 26, 2020
1e4bac0
Merge remote-tracking branch 'upstream/sycl' into sycl-device-triple
bso-intel Sep 3, 2020
ded32d0
Merge remote-tracking branch 'upstream/sycl' into sycl-device-triple
bso-intel Sep 4, 2020
18bb025
refactored with device_filter data structure
bso-intel Sep 4, 2020
0eb0697
clang-format
bso-intel Sep 4, 2020
1b12fb2
Update sycl/include/CL/sycl/detail/device_filter.hpp
bso-intel Sep 8, 2020
c1475c7
added comments about Initialized
bso-intel Sep 8, 2020
1c0226b
added back documentation of new env var
bso-intel Sep 8, 2020
a1f075e
fixed a typo
bso-intel Sep 8, 2020
e0d037f
clarifiied HOST availability for default_selector
bso-intel Sep 10, 2020
7721ca5
typo
bso-intel Sep 10, 2020
432eb20
Update sycl/doc/EnvironmentVariables.md
bso-intel Sep 10, 2020
ff720c4
added deprecation notice
bso-intel Sep 10, 2020
b70a425
Merge branch 'sycl-device-triple' of https://github.com/bso-intel/llv…
bso-intel Sep 10, 2020
7a375f4
typo
bso-intel Sep 10, 2020
52c1c88
added DeviceNum bonus point
bso-intel Sep 11, 2020
c46a497
description change
bso-intel Sep 11, 2020
facf402
format \*
bso-intel Sep 11, 2020
a996dc0
Merge branch 'sycl-device-triple' of https://github.com/bso-intel/llv…
bso-intel Sep 11, 2020
be44799
fix overflow
bso-intel Sep 11, 2020
800afe4
moved loading plugin stmt
bso-intel Sep 11, 2020
dd06217
give bonus points only when backend, device_type, device_num matched.
bso-intel Sep 12, 2020
6864017
clang-format
bso-intel Sep 12, 2020
8494203
change as requested by feedback
bso-intel Sep 13, 2020
156045a
respond to feedback
bso-intel Sep 16, 2020
8de7500
clang-format
bso-intel Sep 16, 2020
39c0725
typo
bso-intel Sep 16, 2020
f7f3718
clang-format
bso-intel Sep 16, 2020
4399a96
respond to more feedback
bso-intel Sep 16, 2020
9b83eee
Update sycl/test/filter_selector/select_device_cpu.cpp
bso-intel Sep 16, 2020
092673f
Update sycl/test/filter_selector/select_device_acc.cpp
bso-intel Sep 16, 2020
84a80ef
Update sycl/test/filter_selector/select_device_acc.cpp
bso-intel Sep 16, 2020
0a0cf63
Update sycl/source/detail/config.hpp
bso-intel Sep 16, 2020
dd12cba
Update sycl/test/filter_selector/select_device_acc.cpp
bso-intel Sep 16, 2020
f3c6387
Update sycl/source/detail/device_filter.cpp
bso-intel Sep 16, 2020
4708688
clang-format
bso-intel Sep 16, 2020
ba2c293
fixed error caused in lambda
bso-intel Sep 17, 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
5 changes: 4 additions & 1 deletion sycl/include/CL/sycl/backend_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {

enum class backend : char { host, opencl, level_zero, cuda };
enum class backend : char { host, opencl, level_zero, cuda, all };

template <backend name, typename SYCLObjectT> struct interop;

Expand All @@ -35,6 +35,9 @@ inline std::ostream &operator<<(std::ostream &Out, backend be) {
break;
case backend::cuda:
Out << std::string("cuda");
break;
case backend::all:
Out << std::string("all");
}
return Out;
}
Expand Down
91 changes: 91 additions & 0 deletions sycl/include/CL/sycl/device_triple.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//==-------------- triple.hpp - SYCL device triple descripter --------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#pragma once

#include <CL/sycl/backend_types.hpp>
#include <CL/sycl/detail/defines.hpp>
#include <CL/sycl/info/info_desc.hpp>

#include <iostream>
#include <string>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {

class device_triple {
backend Backend;
info::device_type DeviceType;
int32_t DeviceNum;
const int DEVICE_NUM_UNSPECIFIED = -1;

public:
device_triple(std::string &TripleString);
backend getBackend() const { return Backend; }
info::device_type getDeviceType() const { return DeviceType; }
int32_t getDeviceNum() const { return DeviceNum; }
friend std::ostream &operator<<(std::ostream &Out, const device_triple &Trp);
};

class device_triple_list {
std::vector<device_triple> TripleList;

public:
device_triple_list(std::string &TripleString);
device_triple_list(device_triple &Trp);
std::vector<device_triple> &get() { return TripleList; }
friend std::ostream &operator<<(std::ostream &Out,
const device_triple_list &List);
};

inline std::ostream &operator<<(std::ostream &Out, const device_triple &Trp) {
switch (Trp.Backend) {
case backend::host:
Out << std::string("host");
break;
case backend::opencl:
Out << std::string("opencl");
break;
case backend::level_zero:
Out << std::string("level-zero");
break;
case backend::cuda:
Out << std::string("cuda");
break;
case backend::all:
Out << std::string("*");
}
Out << std::string(":");
if (Trp.DeviceType == info::device_type::host) {
Out << std::string("host");
} else if (Trp.DeviceType == info::device_type::cpu) {
Out << std::string("cpu");
} else if (Trp.DeviceType == info::device_type::gpu) {
Out << std::string("gpu");
} else if (Trp.DeviceType == info::device_type::accelerator) {
Out << std::string("acceclerator");
} else if (Trp.DeviceType == info::device_type::all) {
Out << std::string("*");
}
if (Trp.DeviceNum != Trp.DEVICE_NUM_UNSPECIFIED) {
Out << std::string(":") << Trp.DeviceNum;
}
return Out;
}

inline std::ostream &operator<<(std::ostream &Out,
const device_triple_list &List) {
for (const device_triple &Trp : List.TripleList) {
Out << Trp;
Out << ",";
}
return Out;
}

} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
1 change: 1 addition & 0 deletions sycl/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ set(SYCL_SOURCES
"context.cpp"
"device.cpp"
"device_selector.cpp"
"device_triple.cpp"
"event.cpp"
"exception.cpp"
"exception_list.cpp"
Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/config.def
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ CONFIG(SYCL_DEVICE_ALLOWLIST, 1024, __SYCL_DEVICE_ALLOWLIST)
CONFIG(SYCL_BE, 16, __SYCL_BE)
CONFIG(SYCL_PI_TRACE, 16, __SYCL_PI_TRACE)
CONFIG(SYCL_DEVICELIB_NO_FALLBACK, 1, __SYCL_DEVICELIB_NO_FALLBACK)
CONFIG(SYCL_DEVICE_TRIPLES, 1024, __SYCL_DEVICE_TRIPLES)
28 changes: 28 additions & 0 deletions sycl/source/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <CL/sycl/backend_types.hpp>
#include <CL/sycl/detail/defines.hpp>
#include <CL/sycl/detail/pi.hpp>
#include <CL/sycl/device_triple.hpp>
#include <CL/sycl/info/info_desc.hpp>

#include <algorithm>
#include <array>
Expand Down Expand Up @@ -163,6 +165,32 @@ template <> class SYCLConfig<SYCL_PI_TRACE> {
}
};

template <> class SYCLConfig<SYCL_DEVICE_TRIPLES> {
using BaseT = SYCLConfigBase<SYCL_DEVICE_TRIPLES>;

public:
static device_triple_list *get() {
static bool Initialized = false;
static device_triple_list *TripleList = nullptr;

// Configuration parameters are processed only once, like reading a string
// from environment and converting it into a typed object.
if (Initialized) {
return TripleList;
}

Initialized = true;
const char *ValStr = BaseT::getRawValue();
if (ValStr) {
std::string TripleString = ValStr;
std::transform(TripleString.begin(), TripleString.end(),
TripleString.begin(), ::tolower);
TripleList = new device_triple_list(TripleString);
}
return TripleList;
}
};

} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
31 changes: 28 additions & 3 deletions sycl/source/detail/pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <CL/sycl/context.hpp>
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/pi.hpp>
#include <CL/sycl/device_triple.hpp>
#include <detail/config.hpp>
#include <detail/plugin.hpp>

Expand Down Expand Up @@ -214,9 +215,33 @@ bool findPlugins(vector_class<std::pair<std::string, backend>> &PluginNames) {
// search is done for libpi_opencl.so/pi_opencl.dll file in LD_LIBRARY_PATH
// env only.
//
PluginNames.emplace_back(OPENCL_PLUGIN_NAME, backend::opencl);
PluginNames.emplace_back(LEVEL_ZERO_PLUGIN_NAME, backend::level_zero);
PluginNames.emplace_back(CUDA_PLUGIN_NAME, backend::cuda);
device_triple_list *TripleList = SYCLConfig<SYCL_DEVICE_TRIPLES>::get();
if (!TripleList) {
PluginNames.emplace_back(OPENCL_PLUGIN_NAME, backend::opencl);
PluginNames.emplace_back(LEVEL_ZERO_PLUGIN_NAME, backend::level_zero);
PluginNames.emplace_back(CUDA_PLUGIN_NAME, backend::cuda);
} else {
std::vector<device_triple> Triples = TripleList->get();
bool OpenCLFound = false;
bool LevelZeroFound = false;
bool CudaFound = false;
for (const device_triple &Trp : Triples) {
backend Backend = Trp.getBackend();
if (!OpenCLFound &&
(Backend == backend::opencl || Backend == backend::all)) {
PluginNames.emplace_back(OPENCL_PLUGIN_NAME, backend::opencl);
OpenCLFound = true;
} else if (!LevelZeroFound &&
(Backend == backend::level_zero || Backend == backend::all)) {
PluginNames.emplace_back(LEVEL_ZERO_PLUGIN_NAME, backend::level_zero);
LevelZeroFound = true;
} else if (!CudaFound &&
(Backend == backend::cuda || Backend == backend::all)) {
PluginNames.emplace_back(CUDA_PLUGIN_NAME, backend::cuda);
CudaFound = true;
}
}
}
return true;
}

Expand Down
114 changes: 114 additions & 0 deletions sycl/source/device_triple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//==------------------- device_triple.cpp ----------------------------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <CL/sycl/device_triple.hpp>
#include <CL/sycl/info/info_desc.hpp>
#include <cstring>
#include <detail/config.hpp>
#include <detail/device_impl.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {

device_triple::device_triple(std::string &TripleString) {
const std::array<std::pair<std::string, info::device_type>, 5>
SyclDeviceTypeMap = {{{"host", info::device_type::host},
{"cpu", info::device_type::cpu},
{"gpu", info::device_type::gpu},
{"acc", info::device_type::accelerator},
{"*", info::device_type::all}}};
const std::array<std::pair<std::string, backend>, 4> SyclBeMap = {
{{"opencl", backend::opencl},
{"level_zero", backend::level_zero},
{"cuda", backend::cuda},
{"*", backend::all}}};

// handle the optional 1st entry, backend
size_t Cursor = 0;
size_t ColonPos = TripleString.find(":", Cursor);
auto It = std::find_if(
std::begin(SyclBeMap), std::end(SyclBeMap),
[=, &Cursor](const std::pair<std::string, backend> &Element) {
size_t Found = TripleString.find(Element.first, Cursor);
if (Found != std::string::npos) {
Cursor = Found;
return true;
}
return false;
});
if (It == SyclBeMap.end()) {
Backend = backend::all;
} else {
Backend = It->second;
if (ColonPos != std::string::npos) {
Cursor = ColonPos + 1;
} else {
Cursor = Cursor + It->first.size();
}
}

// handle the optional 2nd entry, device type
auto Iter = std::find_if(
std::begin(SyclDeviceTypeMap), std::end(SyclDeviceTypeMap),
[=, &Cursor](const std::pair<std::string, info::device_type> &Element) {
size_t Found = TripleString.find(Element.first, Cursor);
if (Found != std::string::npos) {
Cursor = Found;
return true;
}
return false;
});
if (Iter == SyclDeviceTypeMap.end()) {
DeviceType = info::device_type::all;
} else {
DeviceType = Iter->second;
ColonPos = TripleString.find(":", Cursor);
if (ColonPos != std::string::npos) {
Cursor = ColonPos + 1;
} else {
Cursor = Cursor + Iter->first.size();
}
}

// handle the optional 3rd entry, device number
if (Cursor < TripleString.size()) {
try {
DeviceNum = stoi(TripleString.substr(ColonPos + 1));
} catch (...) {
char message[100];
strcpy(message, "Invalid device triple: ");
std::strcat(message, TripleString.c_str());
std::strcat(message,
"\nPossible backend values are {opencl,level_zero,cuda,*}.");
std::strcat(message, "\nPossible device types are {host,cpu,gpu,acc,*}.");
std::strcat(message,
"\nDevice number should be an non-negative integer.\n");
throw cl::sycl::invalid_parameter_error(message, PI_INVALID_VALUE);
}
} else {
DeviceNum = DEVICE_NUM_UNSPECIFIED;
}
}

device_triple_list::device_triple_list(std::string &TripleString) {
std::transform(TripleString.begin(), TripleString.end(), TripleString.begin(),
::tolower);
size_t Pos = 0;
while (Pos < TripleString.size()) {
size_t CommaPos = TripleString.find(",", Pos);
if (CommaPos == std::string::npos) {
CommaPos = TripleString.size();
}
std::string SubString = TripleString.substr(Pos, CommaPos - Pos);
TripleList.push_back(device_triple(SubString));
Pos = CommaPos + 1;
}
}

} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
Loading