QMCPACK
test_SYCLallocator.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2019 QMCPACK developers.
6 //
7 // File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 #include <memory>
16 #include <iostream>
17 #include "SYCL/SYCLallocator.hpp"
18 #include "OhmmsPETE/OhmmsVector.h"
19 
20 namespace qmcplusplus
21 {
22 TEST_CASE("SYCL_allocator", "[SYCL]")
23 {
24  // SYCLAllocator
27  Vector<double> vec_h(1024);
28 
29  double* V = vec.data();
30  m_queue.parallel_for(sycl::range<1>{1024}, [=](sycl::id<1> item) { V[item] = item + 1; });
31 
32  //copy to host
33  m_queue.memcpy(vec_h.data(), vec.data(), 1024 * sizeof(double)).wait();
34 
35  CHECK(vec_h[0] == 1);
36  CHECK(vec_h[77] == 78);
37 }
38 
39 TEST_CASE("SYCL_host_allocator", "[SYCL]")
40 {
42  // SYCLHostAllocator
44 
45  double* V = vec.data();
46  m_queue.parallel_for(sycl::range<1>{1024}, [=](sycl::id<1> item) { V[item] += item + 1; }).wait();
47 
48  CHECK(vec[0] == 2);
49  CHECK(vec[77] == 79);
50 }
51 
52 /*
53 TEST_CASE("SYCL_shared_allocator", "[SYCL]")
54 {
55  sycl::queue m_queue = getSYCLDefaultDeviceDefaultQueue();
56  Vector<double, SYCLSharedAllocator<double>> vec(1024);
57 
58  std::cout << "Size " << vec.size() << std::endl;
59  {
60  double* V = vec.data();
61  m_queue.parallel_for(sycl::range<1>{1024}, [=](sycl::id<1> item) { V[item] = item + 1; }).wait();
62  }
63  CHECK(vec[0] == 1);
64  CHECK(vec[77] == 78);
65 }
66 */
67 
68 } // namespace qmcplusplus
sycl::queue & getSYCLDefaultDeviceDefaultQueue()
return a reference to the per-device default queue
Definition: SYCLruntime.cpp:18
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
Declaraton of Vector<T,Alloc> Manage memory through Alloc directly and allow referencing an existing ...
this file provides three C++ memory allocators using SYCL specific memory allocation functions...
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))