diff --git a/sycl/include/CL/sycl/buffer.hpp b/sycl/include/CL/sycl/buffer.hpp index 8951e4c786f08..c011e1f16130a 100755 --- a/sycl/include/CL/sycl/buffer.hpp +++ b/sycl/include/CL/sycl/buffer.hpp @@ -129,6 +129,17 @@ class buffer { allocator)); } + buffer(const shared_ptr_class &hostData, + const range &bufferRange, AllocatorT allocator, + const property_list &propList = {}) + : Range(bufferRange) { + impl = std::make_shared( + hostData, get_count() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)), + propList, + make_unique_ptr>( + allocator)); + } + buffer(const shared_ptr_class &hostData, const range &bufferRange, const property_list &propList = {}) @@ -139,6 +150,16 @@ class buffer { make_unique_ptr>()); } + buffer(const shared_ptr_class &hostData, + const range &bufferRange, + const property_list &propList = {}) + : Range(bufferRange) { + impl = std::make_shared( + hostData, get_count() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)), + propList, + make_unique_ptr>()); + } + template , typename = EnableIfItInputIterator> diff --git a/sycl/test/basic_tests/buffer/buffer_ctad.cpp b/sycl/test/basic_tests/buffer/buffer_ctad.cpp index 1f7f9fd8ed6e4..07a8afd27318b 100644 --- a/sycl/test/basic_tests/buffer/buffer_ctad.cpp +++ b/sycl/test/basic_tests/buffer/buffer_ctad.cpp @@ -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 #include @@ -19,22 +12,45 @@ int main() { const std::vector cv(5, 1); buffer b1(v.data(), range<1>(5)); static_assert(std::is_same>::value); + buffer b1a(v.data(), range<1>(5), std::allocator()); static_assert( std::is_same>>::value); + buffer b1b(cv.data(), range<1>(5)); static_assert(std::is_same>::value); + buffer b1c(v.data(), range<2>(2, 2)); static_assert(std::is_same>::value); + buffer b2(v.begin(), v.end()); static_assert(std::is_same>::value); + buffer b2a(v.cbegin(), v.cend()); static_assert(std::is_same>::value); + buffer b3(v); static_assert(std::is_same>::value); + buffer b3a(cv); static_assert(std::is_same>::value); + shared_ptr_class ptr{new int[5], [](int *p) { delete[] p; }}; buffer b4(ptr, range<1>(5)); static_assert(std::is_same>::value); + + std::allocator buf_alloc; + shared_ptr_class ptr_alloc{new int[5], [](int *p) { delete[] p; }}; + buffer b5(ptr_alloc, range<1>(5), buf_alloc); + static_assert( + std::is_same>>::value); + + shared_ptr_class arr_ptr{new int[5]}; + buffer b6(arr_ptr, range<1>(5)); + static_assert(std::is_same>::value); + + shared_ptr_class arr_ptr_alloc{new int[5]}; + buffer b7(arr_ptr_alloc, range<1>(5), buf_alloc); + static_assert( + std::is_same>>::value); }