Skip to content

Commit f2ab6f4

Browse files
Replaced use of sycl::vector_class
Added source/vector_type.hpp Declared templated type alias, vector_class_t, defined to use sycl::vector_class for older compiler, and std::vector going forward. Replaced all uses of std::vector/sycl::vector_class with this alias. The packages compiles using open source SYCL compiler after these changes.
1 parent 10db385 commit f2ab6f4

12 files changed

+77
-32
lines changed

dpctl-capi/source/dpctl_sycl_context_interface.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "dpctl_sycl_context_interface.h"
2828
#include "../helper/include/dpctl_async_error_handler.h"
2929
#include "Support/CBindingWrapping.h"
30+
#include "vector_type.hpp"
3031
#include <CL/sycl.hpp>
3132

3233
using namespace cl::sycl;
@@ -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(vector_class_t<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+
vector_class_t<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+
vector_class_t<DPCTLSyclDeviceRef> *DevicesVectorPtr = nullptr;
129130
try {
130-
DevicesVectorPtr = new vector_class<DPCTLSyclDeviceRef>();
131+
DevicesVectorPtr = new vector_class_t<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: 10 additions & 9 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 "dpctl_sycl_device_manager.h"
31+
#include "vector_type.hpp"
3132
#include <CL/sycl.hpp> /* SYCL headers */
3233
#include <algorithm>
3334
#include <cstring>
@@ -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(vector_class_t<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+
vector_class_t<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 vector_class_t<DPCTLSyclDeviceRef>();
623624
for (const auto &sd : subDevices) {
624625
Devices->emplace_back(wrap(new device(sd)));
625626
}
@@ -646,8 +647,8 @@ 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<size_t> vcounts(ncounts);
650+
vector_class_t<DPCTLSyclDeviceRef> *Devices = nullptr;
651+
vector_class_t<size_t> vcounts(ncounts);
651652
vcounts.assign(counts, counts + ncounts);
652653
size_t min_elem = *std::min_element(vcounts.begin(), vcounts.end());
653654
if (min_elem == 0) {
@@ -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+
vector_class_t<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 vector_class_t<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+
vector_class_t<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 vector_class_t<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
@@ -27,6 +27,7 @@
2727
#include "../helper/include/dpctl_utils_helper.h"
2828
#include "Support/CBindingWrapping.h"
2929
#include "dpctl_sycl_enum_types.h"
30+
#include "vector_type.hpp"
3031
#include <CL/sycl.hpp> /* SYCL headers */
3132
#include <iomanip>
3233
#include <iostream>
@@ -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+
vector_class_t<DPCTLSyclDeviceRef> *Devices = nullptr;
146147

147148
try {
148-
Devices = new vector_class<DPCTLSyclDeviceRef>();
149+
Devices = new vector_class_t<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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ __dpctl_give DPCTLSyclDeviceSelectorRef
8383
DPCTLFilterSelector_Create(__dpctl_keep const char *filter_str)
8484
{
8585
try {
86-
auto Selector = new ONEAPI::filter_selector(filter_str);
86+
auto Selector = new ext::oneapi::filter_selector(filter_str);
8787
return wrap(Selector);
8888
} catch (std::bad_alloc &ba) {
8989
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
@@ -27,6 +27,7 @@
2727
#include "dpctl_sycl_event_interface.h"
2828
#include "../helper/include/dpctl_utils_helper.h"
2929
#include "Support/CBindingWrapping.h"
30+
#include "vector_type.hpp"
3031
#include <CL/sycl.hpp> /* SYCL headers */
3132

3233
using namespace cl::sycl;
@@ -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+
vector_class_t<DPCTLSyclEventRef> *EventsVectorPtr = nullptr;
200201
try {
201-
EventsVectorPtr = new vector_class<DPCTLSyclEventRef>();
202+
EventsVectorPtr = new vector_class_t<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
@@ -27,6 +27,7 @@
2727
#include "dpctl_sycl_platform_interface.h"
2828
#include "../helper/include/dpctl_utils_helper.h"
2929
#include "Support/CBindingWrapping.h"
30+
#include "vector_type.hpp"
3031
#include <CL/sycl.hpp>
3132
#include <iomanip>
3233
#include <iostream>
@@ -39,7 +40,7 @@ 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(vector_class_t<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+
vector_class_t<DPCTLSyclPlatformRef> *Platforms = nullptr;
211212

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

214215
try {
215-
Platforms = new vector_class<DPCTLSyclPlatformRef>();
216+
Platforms = new vector_class_t<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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#include "dpctl_sycl_queue_manager.h"
2727
#include "Support/CBindingWrapping.h"
2828
#include "dpctl_sycl_device_manager.h"
29-
#include <CL/sycl.hpp> /* SYCL headers */
30-
#include <vector>
29+
#include "vector_type.hpp" /* vector_class_t */
30+
#include <CL/sycl.hpp> /* SYCL headers */
3131

3232
using namespace cl::sycl;
3333

@@ -43,7 +43,7 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef)
4343

4444
struct QueueManager
4545
{
46-
using QueueStack = vector_class<queue>;
46+
using QueueStack = vector_class_t<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/source/vector_type.hpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===-- vector_type.hpp - Define vector_class_t ===//
2+
//
3+
// Data Parallel Control (dpctl)
4+
//
5+
// Copyright 2020-2021 Intel Corporation
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
//===----------------------------------------------------------------------===//
20+
///
21+
/// \file
22+
/// This file is a private header of DPCTLSyclInterface to define
23+
/// vector_class_t, which used to corresponds to sycl::vector_class in earlier
24+
/// versions of DPC++ and later removed in favor of using std::vector
25+
///
26+
//===----------------------------------------------------------------------===//
27+
28+
#pragma once
29+
30+
#if __SYCL_COMPILER_VERSION < 20210925
31+
#include <CL/sycl.hpp>
32+
template <typename T> using vector_class_t = sycl::vector_class<T>;
33+
#else
34+
#include <vector>
35+
template <typename T> using vector_class_t = std::vector<T>;
36+
#endif

dpctl-capi/tests/test_sycl_context_interface.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
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
{
3940
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(sycl::device, DPCTLSyclDeviceRef);
40-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<DPCTLSyclDeviceRef>,
41+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector<DPCTLSyclDeviceRef>,
4142
DPCTLDeviceVectorRef)
4243
} // namespace
4344

dpctl-capi/tests/test_sycl_event_interface.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
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
{
3738
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(event, DPCTLSyclEventRef);
38-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(vector_class<DPCTLSyclEventRef>,
39+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector<DPCTLSyclEventRef>,
3940
DPCTLEventVectorRef);
4041

4142
#ifndef DPCTL_COVERAGE

dpctl-capi/tests/test_sycl_platform_interface.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@
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+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector<DPCTLSyclPlatformRef>,
4041
DPCTLPlatformVectorRef);
4142

4243
void check_platform_name(__dpctl_keep const DPCTLSyclPlatformRef PRef)

0 commit comments

Comments
 (0)