From 48e2abeeaecf58a4ca2ed653c70379fb1dc0f6a3 Mon Sep 17 00:00:00 2001 From: Vyacheslav N Klochkov Date: Sat, 3 Oct 2020 00:36:06 -0700 Subject: [PATCH 1/4] [SYCL] Fix mem-leak/potential SegFault in LIT test, add 2 required buffer ctors Signed-off-by: Vyacheslav N Klochkov --- sycl/include/CL/sycl/buffer.hpp | 21 +++++++++++++++++++++ sycl/test/basic_tests/buffer/buffer.cpp | 14 +++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/sycl/include/CL/sycl/buffer.hpp b/sycl/include/CL/sycl/buffer.hpp index 14e844f3fb75b..59977d1151dba 100755 --- a/sycl/include/CL/sycl/buffer.hpp +++ b/sycl/include/CL/sycl/buffer.hpp @@ -130,6 +130,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 = {}) @@ -140,6 +151,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.cpp b/sycl/test/basic_tests/buffer/buffer.cpp index 2722afadb2369..1512cfac2c7f7 100644 --- a/sycl/test/basic_tests/buffer/buffer.cpp +++ b/sycl/test/basic_tests/buffer/buffer.cpp @@ -579,9 +579,17 @@ int main() { { std::allocator buf_alloc; - cl::sycl::shared_ptr_class data(new float8[8]); - cl::sycl::buffer> - b(data, cl::sycl::range<1>(8), buf_alloc); + cl::sycl::shared_ptr_class data(new float8[8], + [](float8 *p) { delete[] p; }); + cl::sycl::buffer> b( + data, cl::sycl::range<1>(8), buf_alloc); + } + + { + std::allocator buf_alloc; + cl::sycl::shared_ptr_class data(new float8[8]); + cl::sycl::buffer> b( + data, cl::sycl::range<1>(8), buf_alloc); } { From da51ec6df1858ddb489595eaafd7f9ad6f99d251 Mon Sep 17 00:00:00 2001 From: Vyacheslav N Klochkov Date: Tue, 9 Feb 2021 10:22:49 -0800 Subject: [PATCH 2/4] [SYCL][LIT] Add test cases for new buffer constructors Signed-off-by: Vyacheslav N Klochkov --- sycl/test/basic_tests/buffer/buffer_ctad.cpp | 30 +++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/sycl/test/basic_tests/buffer/buffer_ctad.cpp b/sycl/test/basic_tests/buffer/buffer_ctad.cpp index 1f7f9fd8ed6e4..c5fd634bb819d 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, 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); } From 98ee782893be68b7dfc9b9600100ce4ac8dfbd56 Mon Sep 17 00:00:00 2001 From: Vyacheslav N Klochkov Date: Tue, 9 Feb 2021 10:32:11 -0800 Subject: [PATCH 3/4] clang-format Signed-off-by: Vyacheslav N Klochkov --- sycl/test/basic_tests/buffer/buffer_ctad.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sycl/test/basic_tests/buffer/buffer_ctad.cpp b/sycl/test/basic_tests/buffer/buffer_ctad.cpp index c5fd634bb819d..be685ec7c60e4 100644 --- a/sycl/test/basic_tests/buffer/buffer_ctad.cpp +++ b/sycl/test/basic_tests/buffer/buffer_ctad.cpp @@ -42,8 +42,8 @@ int main() { std::allocator buf_alloc; shared_ptr_class ptr_alloc{new int[5], [](int *p) { delete[] p; }}; buffer b5(ptr, range<1>(5), buf_alloc); - static_assert(std::is_same>>::value); + static_assert( + std::is_same>>::value); shared_ptr_class arr_ptr{new int[5]}; buffer b6(arr_ptr, range<1>(5)); @@ -51,6 +51,6 @@ int main() { 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); + static_assert( + std::is_same>>::value); } From 806566da62542c1a7955fb97558819eaebbfe42f Mon Sep 17 00:00:00 2001 From: Vyacheslav N Klochkov Date: Thu, 11 Feb 2021 09:05:46 -0800 Subject: [PATCH 4/4] Minor additional fix to the LIT test Signed-off-by: Vyacheslav N Klochkov --- sycl/test/basic_tests/buffer/buffer_ctad.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/test/basic_tests/buffer/buffer_ctad.cpp b/sycl/test/basic_tests/buffer/buffer_ctad.cpp index be685ec7c60e4..07a8afd27318b 100644 --- a/sycl/test/basic_tests/buffer/buffer_ctad.cpp +++ b/sycl/test/basic_tests/buffer/buffer_ctad.cpp @@ -41,7 +41,7 @@ int main() { std::allocator buf_alloc; shared_ptr_class ptr_alloc{new int[5], [](int *p) { delete[] p; }}; - buffer b5(ptr, range<1>(5), buf_alloc); + buffer b5(ptr_alloc, range<1>(5), buf_alloc); static_assert( std::is_same>>::value);