ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
MemoryManagerSYCL.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include <Logging.h>
9 
10 #include <cstdlib>
11 #include <sycl/sycl.hpp>
12 #include <unordered_map>
13 
18 
19 namespace cloudViewer {
20 namespace core {
21 
22 void* MemoryManagerSYCL::Malloc(size_t byte_size, const Device& device) {
23  const sycl::queue& queue =
25 
26 #ifdef ENABLE_SYCL_UNIFIED_SHARED_MEMORY
27  return static_cast<void*>(sycl::malloc_shared(byte_size, queue));
28 #else
29  return static_cast<void*>(sycl::malloc_device(byte_size, queue));
30 #endif
31 }
32 
33 void MemoryManagerSYCL::Free(void* ptr, const Device& device) {
34  if (ptr) {
35  const sycl::queue& queue =
37  sycl::free(ptr, queue);
38  }
39 }
40 
41 void MemoryManagerSYCL::Memcpy(void* dst_ptr,
42  const Device& dst_device,
43  const void* src_ptr,
44  const Device& src_device,
45  size_t num_bytes) {
46  Device device_with_queue;
47 
48  if (src_device.IsCPU() && dst_device.IsCPU()) {
50  "Internal error: trying to transfer {}->{}, should not reach "
51  "this function.",
52  src_device.ToString(), dst_device.ToString());
53  } else if (src_device.IsCPU() && dst_device.IsSYCL()) {
54  device_with_queue = dst_device;
55  } else if (src_device.IsSYCL() && dst_device.IsCPU()) {
56  device_with_queue = src_device;
57  } else if (src_device.IsSYCL() && dst_device.IsSYCL()) {
58  device_with_queue = src_device;
59  } else {
60  utility::LogError("Wrong device {}->{}.", src_device.ToString(),
61  dst_device.ToString());
62  }
63 
64  sycl::queue queue =
65  sy::SYCLContext::GetInstance().GetDefaultQueue(device_with_queue);
66  queue.memcpy(dst_ptr, src_ptr, num_bytes).wait_and_throw();
67 }
68 
69 } // namespace core
70 } // namespace cloudViewer
SYCL queue manager.
Common SYCL utilities.
static SYCLContext & GetInstance()
Get singleton instance.
Definition: SYCLContext.cpp:25
sycl::queue GetDefaultQueue(const Device &device)
Get the default SYCL queue given an CloudViewer device.
Definition: SYCLContext.cpp:43
#define LogError(...)
Definition: Logging.h:60
void Free(benchmark::State &state, int size, const Device &device, const MemoryManagerBackend &backend)
void Malloc(benchmark::State &state, int size, const Device &device, const MemoryManagerBackend &backend)
Generic file read and write utility for python interface.