ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ArangeCUDA.cu
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 "core/Dispatch.h"
9 #include "core/ParallelFor.h"
10 #include "core/Tensor.h"
11 #include "core/kernel/Arange.h"
12 
13 namespace cloudViewer {
14 namespace core {
15 namespace kernel {
16 
17 void ArangeCUDA(const Tensor& start,
18  const Tensor& stop,
19  const Tensor& step,
20  Tensor& dst) {
21  Dtype dtype = start.GetDtype();
22  DISPATCH_DTYPE_TO_TEMPLATE(dtype, [&]() {
23  scalar_t sstart = start.Item<scalar_t>();
24  scalar_t sstep = step.Item<scalar_t>();
25  scalar_t* dst_ptr = dst.GetDataPtr<scalar_t>();
26  int64_t n = dst.GetLength();
27  ParallelFor(start.GetDevice(), n,
28  [=] CLOUDVIEWER_HOST_DEVICE(int64_t workload_idx) {
29  dst_ptr[workload_idx] =
30  sstart +
31  static_cast<scalar_t>(sstep * workload_idx);
32  });
33  });
34 }
35 
36 } // namespace kernel
37 } // namespace core
38 } // namespace cloudViewer