Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Device.hpp
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
10#pragma once
11
19#include "shambackends/sycl.hpp"
20#include <cstdint>
21
22namespace sham {
23
24 enum class Vendor { UNKNOWN, NVIDIA, AMD, INTEL, APPLE };
25
32 inline std::string vendor_name(Vendor v) {
33 switch (v) {
34 case Vendor::UNKNOWN: return "Unknown";
35 case Vendor::NVIDIA : return "Nvidia";
36 case Vendor::AMD : return "AMD";
37 case Vendor::INTEL : return "Intel";
38 case Vendor::APPLE : return "Apple";
39 default:
41 "Unknown vendor"); // Throw an exception if the vendor is not recognized
42 }
43 }
44
45 enum class Backend { UNKNOWN, CUDA, ROCM, OPENMP };
46
54 inline std::string backend_name(Backend b) {
55 switch (b) {
56 case Backend::UNKNOWN: return "Unknown";
57 case Backend::CUDA : return "CUDA";
58 case Backend::ROCM : return "ROCm";
59 case Backend::OPENMP : return "OpenMP";
60 default:
62 "Unknown backend"); // Throw an exception if the backend is not recognized
63 }
64 }
65
67 enum class DeviceType { CPU, GPU, UNKNOWN };
68
70 inline std::string device_type_name(DeviceType t) {
71 switch (t) {
72 case DeviceType::CPU: return "CPU";
73 case DeviceType::GPU: return "GPU";
74 default : return "UNKNOWN";
75 }
76 }
77
86 Vendor vendor;
87
89 Backend backend;
90
93
95 std::string name;
96
98 std::string platform;
99
102
105
108
111
114
117
120
123
125 std::vector<size_t> sub_group_sizes;
126
129
131 std::optional<std::string> pci_address;
132
134 std::vector<std::string> warnings;
135 };
136
138 bool is_mpi_direct_capable;
139 };
140
147 class Device {
148 public:
153
157 sycl::device dev;
158
166
171
178 void update_mpi_prop();
179
186 void print_info();
187 };
188
189 std::vector<std::unique_ptr<Device>> get_device_list();
190
191 Device sycl_dev_to_sham_dev(usize i, const sycl::device &dev);
192
193} // namespace sham
std::size_t usize
size_t alias
Represents a SYCL device.
Definition Device.hpp:147
usize device_id
The id of the device.
Definition Device.hpp:152
DeviceMPIProperties mpi_prop
Properties of the device regarding MPI.
Definition Device.hpp:170
sycl::device dev
The SYCL device object.
Definition Device.hpp:157
DeviceProperties prop
Properties of the device.
Definition Device.hpp:165
void update_mpi_prop()
Update the MPI properties of the device.
Definition Device.cpp:485
void print_info()
Print info about the device.
Definition Device.cpp:487
This header file contains utility functions related to exception handling in the code.
namespace for backends this one is named only sham since shambackends is too long to write
std::string backend_name(Backend b)
Returns the name of the given backend.
Definition Device.hpp:54
Device sycl_dev_to_sham_dev(usize i, const sycl::device &dev)
Convert a SYCL device to a shamrock backend device.
Definition Device.cpp:453
std::vector< std::unique_ptr< Device > > get_device_list()
Get a list of all available devices.
Definition Device.cpp:472
std::string vendor_name(Vendor v)
Returns the name of the given vendor.
Definition Device.hpp:32
std::string device_type_name(DeviceType t)
Returns the name of the given device type.
Definition Device.hpp:70
DeviceType
The type of a device.
Definition Device.hpp:67
void throw_unimplemented(SourceLocation loc=SourceLocation{})
Throw a std::runtime_error saying that the function is unimplemented.
Properties of a device.
Definition Device.hpp:84
std::string platform
The name of the platform of the device.
Definition Device.hpp:98
usize global_mem_size
The amount of global memory on the device in bytes.
Definition Device.hpp:101
uint64_t max_mem_alloc_size_dev
The maximum size of memory that can be allocated on the device in bytes.
Definition Device.hpp:116
usize global_mem_cache_size
The amount of global memory cache on the device in bytes.
Definition Device.hpp:107
uint32_t max_compute_units
The number of compute units on the device.
Definition Device.hpp:113
std::vector< std::string > warnings
Warnings emitted during property fetching.
Definition Device.hpp:134
uint32_t mem_base_addr_align
The base address alignment for memory allocations on the device in bytes.
Definition Device.hpp:122
std::optional< std::string > pci_address
PCI address of the device.
Definition Device.hpp:131
usize global_mem_cache_line_size
The size of the cache line used by the device in bytes.
Definition Device.hpp:104
uint32_t default_work_group_size
Default work group size.
Definition Device.hpp:128
uint64_t max_mem_alloc_size_host
The maximum size of memory that can be allocated on the host in bytes.
Definition Device.hpp:119
DeviceType type
The type of the device.
Definition Device.hpp:92
std::vector< size_t > sub_group_sizes
SYCL sub group sizes property.
Definition Device.hpp:125
Vendor vendor
The vendor of the device.
Definition Device.hpp:86
usize local_mem_size
The amount of shared local memory on the device in bytes.
Definition Device.hpp:110
std::string name
The name of the device.
Definition Device.hpp:95
Backend backend
The backend of the device.
Definition Device.hpp:89