Open3D (C++ API)  0.19.0
Loading...
Searching...
No Matches
ParallelForSYCL.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2024 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
8#pragma once
9
10#include <cstdint>
11#include <type_traits>
12
13#include "open3d/core/Device.h"
14#include "open3d/core/Indexer.h"
17
18namespace open3d {
19namespace core {
20
22template <typename Functor, typename... FuncArgs>
23void ParallelForSYCL(const Device& device,
25 FuncArgs... func_args) {
26 if (!device.IsSYCL()) {
27 utility::LogError("ParallelFor for SYCL cannot run on device {}.",
28 device.ToString());
29 }
30 int64_t n = indexer.NumWorkloads();
31 if (n == 0) {
32 return;
33 }
34 auto queue = sy::SYCLContext::GetInstance().GetDefaultQueue(device);
36 queue.parallel_for<Functor>(n, [indexer, func_args...](int64_t i) {
37 Functor ef(indexer, func_args...);
38 ef(i);
39 }).wait_and_throw();
40}
41
43template <typename Functor, typename... FuncArgs>
44void ParallelForSYCL(const Device& device,
45 int64_t num_workloads,
46 FuncArgs... func_args) {
47 if (!device.IsSYCL()) {
48 utility::LogError("ParallelFor for SYCL cannot run on device {}.",
49 device.ToString());
50 }
51 if (num_workloads == 0) {
52 return;
53 }
54 auto queue = sy::SYCLContext::GetInstance().GetDefaultQueue(device);
56 queue.parallel_for<Functor>(num_workloads, [func_args...](int64_t i) {
57 Functor ef(func_args...);
58 ef(i);
59 }).wait_and_throw();
60}
61
62} // namespace core
63} // namespace open3d
Indexer indexer
Definition BinaryEWSYCL.cpp:29
SYCL queue manager.
Definition Device.h:18
bool IsSYCL() const
Returns true iff device type is SYCL GPU.
Definition Device.h:52
std::string ToString() const
Returns string representation of device, e.g. "CPU:0", "CUDA:0".
Definition Device.cpp:88
Definition Indexer.h:261
int64_t NumWorkloads() const
Definition Indexer.cpp:406
static SYCLContext & GetInstance()
Get singleton instance.
Definition SYCLContext.cpp:24
sycl::queue GetDefaultQueue(const Device &device)
Get the default SYCL queue given an Open3D device.
Definition SYCLContext.cpp:42
void ParallelForSYCL(const Device &device, Indexer indexer, FuncArgs... func_args)
Run a function in parallel with SYCL.
Definition ParallelForSYCL.h:23
Definition PinholeCameraIntrinsic.cpp:16