ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
IndexGetSetSYCL.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 
13 
14 namespace cloudViewer {
15 namespace core {
16 namespace kernel {
17 
18 void IndexGetSYCL(const Tensor& src,
19  Tensor& dst,
20  const std::vector<Tensor>& index_tensors,
21  const SizeVector& indexed_shape,
22  const SizeVector& indexed_strides) {
23  Dtype dtype = src.GetDtype();
24  AdvancedIndexer ai(src, dst, index_tensors, indexed_shape, indexed_strides,
26  sycl::queue queue =
28  if (dtype.IsObject()) {
29  int64_t object_byte_size = dtype.ByteSize();
30  for (int64_t idx = 0; idx < ai.NumWorkloads(); ++idx) {
31  queue.memcpy(ai.GetOutputPtr(idx), ai.GetInputPtr(idx),
32  object_byte_size);
33  }
34  } else {
36  queue.parallel_for(ai.NumWorkloads(), [ai](int64_t idx) {
37  // char* -> scalar_t* needs reinterpret_cast
38  *reinterpret_cast<scalar_t*>(ai.GetOutputPtr(idx)) =
39  *reinterpret_cast<const scalar_t*>(
40  ai.GetInputPtr(idx));
41  }).wait_and_throw();
42  });
43  }
44 }
45 
46 void IndexSetSYCL(const Tensor& src,
47  Tensor& dst,
48  const std::vector<Tensor>& index_tensors,
49  const SizeVector& indexed_shape,
50  const SizeVector& indexed_strides) {
51  Dtype dtype = src.GetDtype();
52  AdvancedIndexer ai(src, dst, index_tensors, indexed_shape, indexed_strides,
54  sycl::queue queue =
56  if (dtype.IsObject()) {
57  int64_t object_byte_size = dtype.ByteSize();
58  for (int64_t idx = 0; idx < ai.NumWorkloads(); ++idx) {
59  queue.memcpy(ai.GetOutputPtr(idx), ai.GetInputPtr(idx),
60  object_byte_size);
61  }
62  } else {
64  queue.parallel_for(ai.NumWorkloads(), [ai](int64_t idx) {
65  // char* -> scalar_t* needs reinterpret_cast
66  *reinterpret_cast<scalar_t*>(ai.GetOutputPtr(idx)) =
67  *reinterpret_cast<const scalar_t*>(
68  ai.GetInputPtr(idx));
69  }).wait_and_throw();
70  });
71  }
72 }
73 
74 } // namespace kernel
75 } // namespace core
76 } // namespace cloudViewer
#define DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL(DTYPE,...)
Definition: Dispatch.h:68
SYCL queue manager.
CLOUDVIEWER_HOST_DEVICE char * GetOutputPtr(int64_t workload_idx) const
CLOUDVIEWER_HOST_DEVICE char * GetInputPtr(int64_t workload_idx) const
bool IsObject() const
Definition: Dtype.h:63
int64_t ByteSize() const
Definition: Dtype.h:59
Dtype GetDtype() const
Definition: Tensor.h:1164
Device GetDevice() const override
Definition: Tensor.cpp:1435
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
void IndexSetSYCL(const Tensor &src, Tensor &dst, const std::vector< Tensor > &index_tensors, const SizeVector &indexed_shape, const SizeVector &indexed_strides)
void IndexGetSYCL(const Tensor &src, Tensor &dst, const std::vector< Tensor > &index_tensors, const SizeVector &indexed_shape, const SizeVector &indexed_strides)
Generic file read and write utility for python interface.