Skip to content
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
21 changes: 21 additions & 0 deletions sycl/include/CL/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ class buffer {
allocator));
}

buffer(const shared_ptr_class<T[]> &hostData,
const range<dimensions> &bufferRange, AllocatorT allocator,
const property_list &propList = {})
: Range(bufferRange) {
impl = std::make_shared<detail::buffer_impl>(
hostData, get_count() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)),
propList,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
allocator));
}

buffer(const shared_ptr_class<T> &hostData,
const range<dimensions> &bufferRange,
const property_list &propList = {})
Expand All @@ -139,6 +150,16 @@ class buffer {
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
}

buffer(const shared_ptr_class<T[]> &hostData,
const range<dimensions> &bufferRange,
const property_list &propList = {})
: Range(bufferRange) {
impl = std::make_shared<detail::buffer_impl>(
hostData, get_count() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)),
propList,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
}

template <class InputIterator, int N = dimensions,
typename = EnableIfOneDimension<N>,
typename = EnableIfItInputIterator<InputIterator>>
Expand Down
30 changes: 23 additions & 7 deletions sycl/test/basic_tests/buffer/buffer_ctad.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
// RUN: %clangxx -std=c++17 -fsyntax-only -Xclang -verify %s -I %sycl_include -Xclang -verify-ignore-unexpected=note,warning
// expected-no-diagnostics
//==------------------- buffer_ctad.cpp - SYCL buffer CTAD test ----------------==//
//
// 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.hpp>
#include <cassert>
Expand All @@ -19,22 +12,45 @@ int main() {
const std::vector<int> cv(5, 1);
buffer b1(v.data(), range<1>(5));
static_assert(std::is_same<decltype(b1), buffer<int, 1>>::value);

buffer b1a(v.data(), range<1>(5), std::allocator<int>());
static_assert(
std::is_same<decltype(b1a), buffer<int, 1, std::allocator<int>>>::value);

buffer b1b(cv.data(), range<1>(5));
static_assert(std::is_same<decltype(b1b), buffer<int, 1>>::value);

buffer b1c(v.data(), range<2>(2, 2));
static_assert(std::is_same<decltype(b1c), buffer<int, 2>>::value);

buffer b2(v.begin(), v.end());
static_assert(std::is_same<decltype(b2), buffer<int, 1>>::value);

buffer b2a(v.cbegin(), v.cend());
static_assert(std::is_same<decltype(b2a), buffer<int, 1>>::value);

buffer b3(v);
static_assert(std::is_same<decltype(b3), buffer<int, 1>>::value);

buffer b3a(cv);
static_assert(std::is_same<decltype(b3a), buffer<int, 1>>::value);

shared_ptr_class<int> ptr{new int[5], [](int *p) { delete[] p; }};
buffer b4(ptr, range<1>(5));
static_assert(std::is_same<decltype(b4), buffer<int, 1>>::value);

std::allocator<int> buf_alloc;
shared_ptr_class<int> ptr_alloc{new int[5], [](int *p) { delete[] p; }};
buffer b5(ptr_alloc, range<1>(5), buf_alloc);
static_assert(
std::is_same<decltype(b5), buffer<int, 1, std::allocator<int>>>::value);

shared_ptr_class<int[]> arr_ptr{new int[5]};
buffer b6(arr_ptr, range<1>(5));
static_assert(std::is_same<decltype(b6), buffer<int, 1>>::value);

shared_ptr_class<int[]> arr_ptr_alloc{new int[5]};
buffer b7(arr_ptr_alloc, range<1>(5), buf_alloc);
static_assert(
std::is_same<decltype(b7), buffer<int, 1, std::allocator<int>>>::value);
}