Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
DeviceContext.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
17#include "shamcomm/logs.hpp"
18
19namespace sham {
20
21 auto exception_handler = [](const sycl::exception_list &exceptions) {
22 for (std::exception_ptr const &e : exceptions) {
23 try {
24 std::rethrow_exception(e);
25 } catch (sycl::exception const &e) {
26 printf("Caught synchronous SYCL exception: %s\n", e.what());
27 }
28 }
29 };
30
34 auto ctx_init = [](std::shared_ptr<Device> &dev) -> sycl::context {
35 if (!bool(dev)) {
37 }
38 return sycl::context(dev->dev, exception_handler);
39 };
40
41 DeviceContext::DeviceContext(std::shared_ptr<Device> dev)
42 : device(std::move(dev)), ctx(ctx_init(device)) {}
43
45 device->print_info();
46
47 shamcomm::logs::raw_ln(" Context info");
48
49 // deprecated in DPCPP and does not really make sense in acpp either
50 // logger::raw_ln(" - is_host() :", ctx.is_host());
51
52 // #ifdef SYCL_COMP_ACPP
53 // logger::raw_ln(" - hipSYCL_hash_code() :", ctx.hipSYCL_hash_code());
54 // #endif
55 }
56
58
59 if (!bool(device)) {
60 shambase::throw_with_loc<std::runtime_error>("Why is device not allocated");
61 }
62
63 auto &dev = *device;
64 return dev.mpi_prop.is_mpi_direct_capable;
65 }
66
67} // namespace sham
void print_info()
Print information about this context.
std::shared_ptr< Device > device
bool use_direct_comm()
Check if the context should use direct communication.
DeviceContext(std::shared_ptr< Device > device)
Construct a new Device Context object.
namespace for backends this one is named only sham since shambackends is too long to write
@ device
Device memory.
auto ctx_init
Lambda used to provide sycl::context initialization.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
STL namespace.