Skip to content

Commit bdfad9e

Browse files
authored
[SYCL] Add two required buffer ctors (#2591)
Signed-off-by: Vyacheslav N Klochkov <[email protected]>
1 parent f9241e0 commit bdfad9e

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

sycl/include/CL/sycl/buffer.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ class buffer {
129129
allocator));
130130
}
131131

132+
buffer(const shared_ptr_class<T[]> &hostData,
133+
const range<dimensions> &bufferRange, AllocatorT allocator,
134+
const property_list &propList = {})
135+
: Range(bufferRange) {
136+
impl = std::make_shared<detail::buffer_impl>(
137+
hostData, get_count() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)),
138+
propList,
139+
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
140+
allocator));
141+
}
142+
132143
buffer(const shared_ptr_class<T> &hostData,
133144
const range<dimensions> &bufferRange,
134145
const property_list &propList = {})
@@ -139,6 +150,16 @@ class buffer {
139150
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
140151
}
141152

153+
buffer(const shared_ptr_class<T[]> &hostData,
154+
const range<dimensions> &bufferRange,
155+
const property_list &propList = {})
156+
: Range(bufferRange) {
157+
impl = std::make_shared<detail::buffer_impl>(
158+
hostData, get_count() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)),
159+
propList,
160+
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
161+
}
162+
142163
template <class InputIterator, int N = dimensions,
143164
typename = EnableIfOneDimension<N>,
144165
typename = EnableIfItInputIterator<InputIterator>>
Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
// RUN: %clangxx -std=c++17 -fsyntax-only -Xclang -verify %s -I %sycl_include -Xclang -verify-ignore-unexpected=note,warning
22
// expected-no-diagnostics
3-
//==------------------- buffer_ctad.cpp - SYCL buffer CTAD test ----------------==//
4-
//
5-
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6-
// See https://llvm.org/LICENSE.txt for license information.
7-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8-
//
9-
//===----------------------------------------------------------------------===//
103

114
#include <CL/sycl.hpp>
125
#include <cassert>
@@ -19,22 +12,45 @@ int main() {
1912
const std::vector<int> cv(5, 1);
2013
buffer b1(v.data(), range<1>(5));
2114
static_assert(std::is_same<decltype(b1), buffer<int, 1>>::value);
15+
2216
buffer b1a(v.data(), range<1>(5), std::allocator<int>());
2317
static_assert(
2418
std::is_same<decltype(b1a), buffer<int, 1, std::allocator<int>>>::value);
19+
2520
buffer b1b(cv.data(), range<1>(5));
2621
static_assert(std::is_same<decltype(b1b), buffer<int, 1>>::value);
22+
2723
buffer b1c(v.data(), range<2>(2, 2));
2824
static_assert(std::is_same<decltype(b1c), buffer<int, 2>>::value);
25+
2926
buffer b2(v.begin(), v.end());
3027
static_assert(std::is_same<decltype(b2), buffer<int, 1>>::value);
28+
3129
buffer b2a(v.cbegin(), v.cend());
3230
static_assert(std::is_same<decltype(b2a), buffer<int, 1>>::value);
31+
3332
buffer b3(v);
3433
static_assert(std::is_same<decltype(b3), buffer<int, 1>>::value);
34+
3535
buffer b3a(cv);
3636
static_assert(std::is_same<decltype(b3a), buffer<int, 1>>::value);
37+
3738
shared_ptr_class<int> ptr{new int[5], [](int *p) { delete[] p; }};
3839
buffer b4(ptr, range<1>(5));
3940
static_assert(std::is_same<decltype(b4), buffer<int, 1>>::value);
41+
42+
std::allocator<int> buf_alloc;
43+
shared_ptr_class<int> ptr_alloc{new int[5], [](int *p) { delete[] p; }};
44+
buffer b5(ptr_alloc, range<1>(5), buf_alloc);
45+
static_assert(
46+
std::is_same<decltype(b5), buffer<int, 1, std::allocator<int>>>::value);
47+
48+
shared_ptr_class<int[]> arr_ptr{new int[5]};
49+
buffer b6(arr_ptr, range<1>(5));
50+
static_assert(std::is_same<decltype(b6), buffer<int, 1>>::value);
51+
52+
shared_ptr_class<int[]> arr_ptr_alloc{new int[5]};
53+
buffer b7(arr_ptr_alloc, range<1>(5), buf_alloc);
54+
static_assert(
55+
std::is_same<decltype(b7), buffer<int, 1, std::allocator<int>>>::value);
4056
}

0 commit comments

Comments
 (0)