ACloudViewer
3.9.4
A Modern Library for 3D Data Processing
ParallelForSYCL.h
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
#pragma once
9
10
#include <
Logging.h
>
11
12
#include <cstdint>
13
#include <type_traits>
14
15
#include "
cloudViewer/core/Device.h
"
16
#include "
cloudViewer/core/Indexer.h
"
17
#include "
cloudViewer/core/SYCLContext.h
"
18
19
namespace
cloudViewer
{
20
namespace
core {
21
23
template
<
typename
Functor,
typename
... FuncArgs>
24
void
ParallelForSYCL
(
const
Device
& device,
25
Indexer
indexer
,
26
FuncArgs... func_args) {
27
if
(!device.
IsSYCL
()) {
28
utility::LogError
(
"ParallelFor for SYCL cannot run on device {}."
,
29
device.
ToString
());
30
}
31
int64_t n =
indexer
.
NumWorkloads
();
32
if
(n == 0) {
33
return
;
34
}
35
auto
queue =
sy::SYCLContext::GetInstance
().
GetDefaultQueue
(device);
37
queue.parallel_for<Functor>(n, [
indexer
, func_args...](int64_t i) {
38
Functor ef(
indexer
, func_args...);
39
ef(i);
40
}).wait_and_throw();
41
}
42
44
template
<
typename
Functor,
typename
... FuncArgs>
45
void
ParallelForSYCL
(
const
Device
& device,
46
int64_t num_workloads,
47
FuncArgs... func_args) {
48
if
(!device.
IsSYCL
()) {
49
utility::LogError
(
"ParallelFor for SYCL cannot run on device {}."
,
50
device.
ToString
());
51
}
52
if
(num_workloads == 0) {
53
return
;
54
}
55
auto
queue =
sy::SYCLContext::GetInstance
().
GetDefaultQueue
(device);
57
queue.parallel_for<Functor>(num_workloads, [func_args...](int64_t i) {
58
Functor ef(func_args...);
59
ef(i);
60
}).wait_and_throw();
61
}
62
63
}
// namespace core
64
}
// namespace cloudViewer
indexer
Indexer indexer
Definition:
BinaryEWSYCL.cpp:30
Device.h
Indexer.h
SYCLContext.h
SYCL queue manager.
cloudViewer::core::Device
Definition:
Device.h:18
cloudViewer::core::Device::ToString
std::string ToString() const
Returns string representation of device, e.g. "CPU:0", "CUDA:0".
Definition:
Device.cpp:89
cloudViewer::core::Device::IsSYCL
bool IsSYCL() const
Returns true iff device type is SYCL GPU.
Definition:
Device.h:52
cloudViewer::core::Indexer
Definition:
Indexer.h:262
cloudViewer::core::Indexer::NumWorkloads
int64_t NumWorkloads() const
Definition:
Indexer.cpp:406
cloudViewer::core::sy::SYCLContext::GetInstance
static SYCLContext & GetInstance()
Get singleton instance.
Definition:
SYCLContext.cpp:25
cloudViewer::core::sy::SYCLContext::GetDefaultQueue
sycl::queue GetDefaultQueue(const Device &device)
Get the default SYCL queue given an CloudViewer device.
Definition:
SYCLContext.cpp:43
LogError
#define LogError(...)
Definition:
Logging.h:60
Logging.h
cloudViewer::core::ParallelForSYCL
void ParallelForSYCL(const Device &device, Indexer indexer, FuncArgs... func_args)
Run a function in parallel with SYCL.
Definition:
ParallelForSYCL.h:24
cloudViewer
Generic file read and write utility for python interface.
Definition:
AutoSegmentationTools.h:16
libs
cloudViewer
core
ParallelForSYCL.h
Generated on Wed Jan 28 2026 09:00:54 for ACloudViewer by
1.9.1