Skip to content

Commit 59d4d65

Browse files
Remove use of DPC++ features deprecated in 2021.4 and open source intel/llvm compiler (#603)
* Removed sycl::vector_class, use std::vector throughout sycl::vector_class is deprecated in 2021.4, and completly removed in open source compiler. The packages compiles using open source SYCL compiler after these changes. * Use preprocessor to be able to build dpctl with oneAPI 2021.3 In oneAPI 2021.3 the namespace of filter_selector class is different * Remove unused declaration of data conversions Remove all uses of type conversions of Vector and underlyng C++ classes Used DPCTLDevice_CreateSubDevicesEqually instead of building the vector explicitly and casting it to DPCTLDeviceVectorRef. * Bumped up minimal required DPC++ version
2 parents a8f4254 + ab07506 commit 59d4d65

12 files changed

+59
-72
lines changed

dpctl-capi/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ option(DPCTL_BUILD_CAPI_TESTS
4141

4242
# Minimum version requirement only when oneAPI dpcpp is used.
4343
if(DPCTL_DPCPP_FROM_ONEAPI)
44-
find_package(IntelSycl 2021.2.0 REQUIRED)
44+
find_package(IntelSycl 2021.3.0 REQUIRED)
4545
else()
4646
find_package(IntelSycl REQUIRED)
4747
endif()

dpctl-capi/source/dpctl_sycl_context_interface.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "../helper/include/dpctl_async_error_handler.h"
2929
#include "Support/CBindingWrapping.h"
3030
#include <CL/sycl.hpp>
31+
#include <vector>
3132

3233
using namespace cl::sycl;
3334

@@ -36,7 +37,7 @@ namespace
3637
// Create wrappers for C Binding types (see CBindingWrapping.h).
3738
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef)
3839
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef)
39-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<DPCTLSyclDeviceRef>,
40+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector<DPCTLSyclDeviceRef>,
4041
DPCTLDeviceVectorRef)
4142
} /* end of anonymous namespace */
4243

@@ -67,7 +68,7 @@ DPCTLContext_CreateFromDevices(__dpctl_keep const DPCTLDeviceVectorRef DVRef,
6768
int /**/)
6869
{
6970
DPCTLSyclContextRef CRef = nullptr;
70-
vector_class<device> Devices;
71+
std::vector<device> Devices;
7172
auto DeviceRefs = unwrap(DVRef);
7273
if (!DeviceRefs)
7374
return CRef;
@@ -125,9 +126,9 @@ DPCTLContext_GetDevices(__dpctl_keep const DPCTLSyclContextRef CRef)
125126
"input is a nullptr\n";
126127
return nullptr;
127128
}
128-
vector_class<DPCTLSyclDeviceRef> *DevicesVectorPtr = nullptr;
129+
std::vector<DPCTLSyclDeviceRef> *DevicesVectorPtr = nullptr;
129130
try {
130-
DevicesVectorPtr = new vector_class<DPCTLSyclDeviceRef>();
131+
DevicesVectorPtr = new std::vector<DPCTLSyclDeviceRef>();
131132
} catch (std::bad_alloc const &ba) {
132133
// \todo log error
133134
std::cerr << ba.what() << '\n';

dpctl-capi/source/dpctl_sycl_device_interface.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <CL/sycl.hpp> /* SYCL headers */
3232
#include <algorithm>
3333
#include <cstring>
34+
#include <vector>
3435

3536
using namespace cl::sycl;
3637

@@ -40,7 +41,7 @@ namespace
4041
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device, DPCTLSyclDeviceRef)
4142
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device_selector, DPCTLSyclDeviceSelectorRef)
4243
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef)
43-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<DPCTLSyclDeviceRef>,
44+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector<DPCTLSyclDeviceRef>,
4445
DPCTLDeviceVectorRef)
4546

4647
} /* end of anonymous namespace */
@@ -608,7 +609,7 @@ __dpctl_give DPCTLDeviceVectorRef
608609
DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef,
609610
size_t count)
610611
{
611-
vector_class<DPCTLSyclDeviceRef> *Devices = nullptr;
612+
std::vector<DPCTLSyclDeviceRef> *Devices = nullptr;
612613
if (DRef) {
613614
if (count == 0) {
614615
std::cerr << "Can not create sub-devices with zero compute units"
@@ -619,7 +620,7 @@ DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef,
619620
try {
620621
auto subDevices = D->create_sub_devices<
621622
info::partition_property::partition_equally>(count);
622-
Devices = new vector_class<DPCTLSyclDeviceRef>();
623+
Devices = new std::vector<DPCTLSyclDeviceRef>();
623624
for (const auto &sd : subDevices) {
624625
Devices->emplace_back(wrap(new device(sd)));
625626
}
@@ -646,7 +647,7 @@ DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef,
646647
__dpctl_keep size_t *counts,
647648
size_t ncounts)
648649
{
649-
vector_class<DPCTLSyclDeviceRef> *Devices = nullptr;
650+
std::vector<DPCTLSyclDeviceRef> *Devices = nullptr;
650651
std::vector<size_t> vcounts(ncounts);
651652
vcounts.assign(counts, counts + ncounts);
652653
size_t min_elem = *std::min_element(vcounts.begin(), vcounts.end());
@@ -657,7 +658,7 @@ DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef,
657658
}
658659
if (DRef) {
659660
auto D = unwrap(DRef);
660-
vector_class<std::remove_pointer<decltype(D)>::type> subDevices;
661+
std::vector<std::remove_pointer<decltype(D)>::type> subDevices;
661662
try {
662663
subDevices = D->create_sub_devices<
663664
info::partition_property::partition_by_counts>(vcounts);
@@ -670,7 +671,7 @@ DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef,
670671
return nullptr;
671672
}
672673
try {
673-
Devices = new vector_class<DPCTLSyclDeviceRef>();
674+
Devices = new std::vector<DPCTLSyclDeviceRef>();
674675
for (const auto &sd : subDevices) {
675676
Devices->emplace_back(wrap(new device(sd)));
676677
}
@@ -692,15 +693,15 @@ __dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity(
692693
__dpctl_keep const DPCTLSyclDeviceRef DRef,
693694
DPCTLPartitionAffinityDomainType PartitionAffinityDomainTy)
694695
{
695-
vector_class<DPCTLSyclDeviceRef> *Devices = nullptr;
696+
std::vector<DPCTLSyclDeviceRef> *Devices = nullptr;
696697
auto D = unwrap(DRef);
697698
if (D) {
698699
try {
699700
auto domain = DPCTL_DPCTLPartitionAffinityDomainTypeToSycl(
700701
PartitionAffinityDomainTy);
701702
auto subDevices = D->create_sub_devices<
702703
info::partition_property::partition_by_affinity_domain>(domain);
703-
Devices = new vector_class<DPCTLSyclDeviceRef>();
704+
Devices = new std::vector<DPCTLSyclDeviceRef>();
704705
for (const auto &sd : subDevices) {
705706
Devices->emplace_back(wrap(new device(sd)));
706707
}

dpctl-capi/source/dpctl_sycl_device_manager.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <iomanip>
3232
#include <iostream>
3333
#include <unordered_map>
34+
#include <vector>
3435

3536
using namespace cl::sycl;
3637

@@ -142,10 +143,10 @@ DPCTLDeviceMgr_GetCachedContext(__dpctl_keep const DPCTLSyclDeviceRef DRef)
142143
__dpctl_give DPCTLDeviceVectorRef
143144
DPCTLDeviceMgr_GetDevices(int device_identifier)
144145
{
145-
vector_class<DPCTLSyclDeviceRef> *Devices = nullptr;
146+
std::vector<DPCTLSyclDeviceRef> *Devices = nullptr;
146147

147148
try {
148-
Devices = new vector_class<DPCTLSyclDeviceRef>();
149+
Devices = new std::vector<DPCTLSyclDeviceRef>();
149150
} catch (std::bad_alloc const &ba) {
150151
delete Devices;
151152
return nullptr;

dpctl-capi/source/dpctl_sycl_device_selector_interface.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,13 @@ __dpctl_give DPCTLSyclDeviceSelectorRef DPCTLCPUSelector_Create()
8282
__dpctl_give DPCTLSyclDeviceSelectorRef
8383
DPCTLFilterSelector_Create(__dpctl_keep const char *filter_str)
8484
{
85+
#if __SYCL_COMPILER_VERSION < 20210925
86+
using filter_selector_t = sycl::ONEAPI::filter_selector;
87+
#else
88+
using filter_selector_t = sycl::ext::oneapi::filter_selector;
89+
#endif
8590
try {
86-
auto Selector = new ONEAPI::filter_selector(filter_str);
91+
auto Selector = new filter_selector_t(filter_str);
8792
return wrap(Selector);
8893
} catch (std::bad_alloc &ba) {
8994
std::cerr << ba.what() << '\n';

dpctl-capi/source/dpctl_sycl_event_interface.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "../helper/include/dpctl_utils_helper.h"
2929
#include "Support/CBindingWrapping.h"
3030
#include <CL/sycl.hpp> /* SYCL headers */
31+
#include <vector>
3132

3233
using namespace cl::sycl;
3334

@@ -196,9 +197,9 @@ DPCTLEvent_GetWaitList(__dpctl_keep DPCTLSyclEventRef ERef)
196197
std::cerr << "Cannot get wait list as input is a nullptr\n";
197198
return nullptr;
198199
}
199-
vector_class<DPCTLSyclEventRef> *EventsVectorPtr = nullptr;
200+
std::vector<DPCTLSyclEventRef> *EventsVectorPtr = nullptr;
200201
try {
201-
EventsVectorPtr = new vector_class<DPCTLSyclEventRef>();
202+
EventsVectorPtr = new std::vector<DPCTLSyclEventRef>();
202203
} catch (std::bad_alloc const &ba) {
203204
// \todo log error
204205
std::cerr << ba.what() << '\n';

dpctl-capi/source/dpctl_sycl_platform_interface.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232
#include <iostream>
3333
#include <set>
3434
#include <sstream>
35+
#include <vector>
3536

3637
using namespace cl::sycl;
3738

3839
namespace
3940
{
4041
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef);
4142
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device_selector, DPCTLSyclDeviceSelectorRef);
42-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<DPCTLSyclPlatformRef>,
43+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector<DPCTLSyclPlatformRef>,
4344
DPCTLPlatformVectorRef);
4445
} // namespace
4546

@@ -207,12 +208,12 @@ DPCTLPlatform_GetVersion(__dpctl_keep const DPCTLSyclPlatformRef PRef)
207208

208209
__dpctl_give DPCTLPlatformVectorRef DPCTLPlatform_GetPlatforms()
209210
{
210-
vector_class<DPCTLSyclPlatformRef> *Platforms = nullptr;
211+
std::vector<DPCTLSyclPlatformRef> *Platforms = nullptr;
211212

212213
auto platforms = platform::get_platforms();
213214

214215
try {
215-
Platforms = new vector_class<DPCTLSyclPlatformRef>();
216+
Platforms = new std::vector<DPCTLSyclPlatformRef>();
216217
Platforms->reserve(platforms.size());
217218
} catch (std::bad_alloc const &ba) {
218219
return nullptr;

dpctl-capi/source/dpctl_sycl_queue_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef)
4343

4444
struct QueueManager
4545
{
46-
using QueueStack = vector_class<queue>;
46+
using QueueStack = std::vector<queue>;
4747
static QueueStack &getQueueStack()
4848
{
4949
thread_local static QueueStack *activeQueues = new QueueStack([] {

dpctl-capi/source/dpctl_vector_templ.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
#include "../helper/include/dpctl_vector_macros.h"
2727
#include "Support/MemOwnershipAttrs.h"
2828
#include <type_traits>
29+
#include <vector>
2930

3031
namespace
3132
{
32-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<SYCLREF(EL)>, VECTOR(EL))
33+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector<SYCLREF(EL)>, VECTOR(EL))
3334
}
3435

3536
/*!
@@ -39,9 +40,9 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<SYCLREF(EL)>, VECTOR(EL))
3940
*/
4041
__dpctl_give VECTOR(EL) FN(EL, Create)()
4142
{
42-
vector_class<SYCLREF(EL)> *Vec = nullptr;
43+
std::vector<SYCLREF(EL)> *Vec = nullptr;
4344
try {
44-
Vec = new vector_class<SYCLREF(EL)>();
45+
Vec = new std::vector<SYCLREF(EL)>();
4546
return wrap(Vec);
4647
} catch (std::bad_alloc const &ba) {
4748
delete Vec;
@@ -58,9 +59,9 @@ __dpctl_give VECTOR(EL) FN(EL, Create)()
5859
__dpctl_give VECTOR(EL)
5960
FN(EL, CreateFromArray)(size_t n, __dpctl_keep SYCLREF(EL) * elems)
6061
{
61-
vector_class<SYCLREF(EL)> *Vec = nullptr;
62+
std::vector<SYCLREF(EL)> *Vec = nullptr;
6263
try {
63-
Vec = new vector_class<SYCLREF(EL)>();
64+
Vec = new std::vector<SYCLREF(EL)>();
6465
for (size_t i = 0; i < n; ++i) {
6566
auto Ref = unwrap(elems[i]);
6667
Vec->emplace_back(

dpctl-capi/tests/test_sycl_context_interface.cpp

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@
3131
#include "dpctl_sycl_types.h"
3232
#include <CL/sycl.hpp>
3333
#include <gtest/gtest.h>
34+
#include <vector>
3435

3536
using namespace cl::sycl;
3637

3738
namespace
3839
{
39-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(sycl::device, DPCTLSyclDeviceRef);
40-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<DPCTLSyclDeviceRef>,
41-
DPCTLDeviceVectorRef)
4240
} // namespace
4341

4442
struct TestDPCTLContextInterface : public ::testing::TestWithParam<const char *>
@@ -83,25 +81,16 @@ TEST_P(TestDPCTLContextInterface, ChkCreateWithDevices)
8381
DPCTLSyclContextRef CRef = nullptr;
8482
DPCTLDeviceVectorRef DVRef = nullptr;
8583

86-
/* TODO: Once we have wrappers for sub-device creation let us use those
87-
* functions.
88-
*/
8984
EXPECT_NO_FATAL_FAILURE(nCUs = DPCTLDevice_GetMaxComputeUnits(DRef));
90-
if (nCUs) {
91-
auto D = unwrap(DRef);
92-
try {
93-
auto subDevices = D->create_sub_devices<
94-
info::partition_property::partition_equally>(nCUs / 2);
95-
EXPECT_NO_FATAL_FAILURE(DVRef = DPCTLDeviceVector_Create());
96-
for (auto &sd : subDevices) {
97-
unwrap(DVRef)->emplace_back(wrap(new device(sd)));
98-
}
99-
EXPECT_NO_FATAL_FAILURE(
100-
CRef = DPCTLContext_CreateFromDevices(DVRef, nullptr, 0));
101-
ASSERT_TRUE(CRef);
102-
} catch (feature_not_supported const &fnse) {
85+
if (nCUs > 1) {
86+
EXPECT_NO_FATAL_FAILURE(
87+
DVRef = DPCTLDevice_CreateSubDevicesEqually(DRef, nCUs / 2));
88+
if (!DVRef) {
10389
GTEST_SKIP_("Skipping creating context for sub-devices");
10490
}
91+
EXPECT_NO_FATAL_FAILURE(
92+
CRef = DPCTLContext_CreateFromDevices(DVRef, nullptr, 0));
93+
ASSERT_TRUE(CRef);
10594
}
10695
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef));
10796
EXPECT_NO_FATAL_FAILURE(DPCTLContext_Delete(CRef));
@@ -118,28 +107,19 @@ TEST_P(TestDPCTLContextInterface, ChkCreateWithDevicesGetDevices)
118107
* functions.
119108
*/
120109
EXPECT_NO_FATAL_FAILURE(nCUs = DPCTLDevice_GetMaxComputeUnits(DRef));
121-
if (nCUs) {
122-
auto D = unwrap(DRef);
123-
try {
124-
auto subDevices = D->create_sub_devices<
125-
info::partition_property::partition_equally>(nCUs / 2);
126-
const size_t len = subDevices.size();
127-
auto ar = new DPCTLSyclDeviceRef[len];
128-
for (size_t i = 0; i < len; ++i) {
129-
ar[i] = wrap(&subDevices.at(i));
130-
}
131-
EXPECT_NO_FATAL_FAILURE(
132-
DVRef = DPCTLDeviceVector_CreateFromArray(len, ar));
133-
EXPECT_NO_FATAL_FAILURE(
134-
CRef = DPCTLContext_CreateFromDevices(DVRef, nullptr, 0));
135-
ASSERT_TRUE(CRef);
136-
ASSERT_TRUE(DPCTLContext_DeviceCount(CRef) == len);
137-
EXPECT_NO_FATAL_FAILURE(Res_DVRef = DPCTLContext_GetDevices(CRef));
138-
ASSERT_TRUE(DPCTLDeviceVector_Size(Res_DVRef) == len);
139-
delete[] ar;
140-
} catch (feature_not_supported const &fnse) {
110+
if (nCUs > 1) {
111+
EXPECT_NO_FATAL_FAILURE(
112+
DVRef = DPCTLDevice_CreateSubDevicesEqually(DRef, nCUs / 2));
113+
if (!DVRef) {
141114
GTEST_SKIP_("Skipping creating context for sub-devices");
142115
}
116+
EXPECT_NO_FATAL_FAILURE(
117+
CRef = DPCTLContext_CreateFromDevices(DVRef, nullptr, 0));
118+
ASSERT_TRUE(CRef);
119+
const size_t len = DPCTLDeviceVector_Size(DVRef);
120+
ASSERT_TRUE(DPCTLContext_DeviceCount(CRef) == len);
121+
EXPECT_NO_FATAL_FAILURE(Res_DVRef = DPCTLContext_GetDevices(CRef));
122+
ASSERT_TRUE(DPCTLDeviceVector_Size(Res_DVRef) == len);
143123
}
144124
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceVector_Delete(DVRef));
145125
EXPECT_NO_FATAL_FAILURE(DPCTLContext_Delete(CRef));

dpctl-capi/tests/test_sycl_event_interface.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@
2929
#include "dpctl_sycl_types.h"
3030
#include <CL/sycl.hpp>
3131
#include <gtest/gtest.h>
32+
#include <vector>
3233

3334
using namespace cl::sycl;
3435

3536
namespace
3637
{
37-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPCTLSyclEventRef);
38-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<DPCTLSyclEventRef>,
39-
DPCTLEventVectorRef);
40-
4138
#ifndef DPCTL_COVERAGE
4239
sycl::event produce_event(sycl::queue &Q, sycl::buffer<int> &data)
4340
{

dpctl-capi/tests/test_sycl_platform_interface.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@
3131
#include "dpctl_utils.h"
3232
#include <CL/sycl.hpp>
3333
#include <gtest/gtest.h>
34+
#include <vector>
3435

3536
using namespace cl::sycl;
3637

3738
namespace
3839
{
39-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<DPCTLSyclPlatformRef>,
40-
DPCTLPlatformVectorRef);
4140

4241
void check_platform_name(__dpctl_keep const DPCTLSyclPlatformRef PRef)
4342
{

0 commit comments

Comments
 (0)