Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
pyNodeInstance.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
17
19#include "shamcmdopt/cmdopt.hpp"
20#include "shamcomm/mpiInfo.hpp"
21#include "shamcomm/wrapper.hpp"
24#include <pybind11/stl.h>
25
26namespace shamsys::instance {
27 void register_pymodules(py::module &m) {
28
29 using namespace shamsys::instance;
30
31 m.def(
32 "init",
33 [](std::string sycl_cfg) {
35 sycl_cfg, MPIInitInfo{.argc = opts::get_argc(), .argv = opts::get_argv()});
36 },
37 R"pbdoc(
38
39 The init function for shamrock node instance
40
41 )pbdoc");
42
43 m.def(
44 "close",
45 []() {
46 close();
47 },
48 R"pbdoc(
49
50 The close function for shamrock node instance
51
52 )pbdoc");
53
54 m.def("get_process_name", &shamcomm::get_process_name, R"pbdoc(
55
56 Get the name of the process
57
58 )pbdoc");
59
60 m.def(
61 "world_rank",
62 []() {
63 return shamcomm::world_rank();
64 },
65 R"pbdoc(
66 Get the world rank
67 )pbdoc");
68
69 m.def(
70 "world_size",
71 []() {
72 return shamcomm::world_size();
73 },
74 R"pbdoc(
75 Get the world size
76 )pbdoc");
77
78 m.def(
79 "is_initialized",
80 []() {
81 return is_initialized();
82 },
83 R"pbdoc(
84 Return true if the node instance is initialized
85 )pbdoc");
86
87 m.def(
88 "mpi_barrier",
89 []() {
90 shamcomm::mpi::Barrier(MPI_COMM_WORLD);
91 },
92 R"pbdoc(
93 Call the MPI barrier
94 )pbdoc");
95
96 m.def(
97 "get_compute_device_properties",
98 []() {
99 auto &sched = shamsys::instance::get_compute_scheduler();
100 auto &dev = shambase::get_check_ref(sched.ctx).device;
101 auto &prop = shambase::get_check_ref(dev).prop;
102
103 py::dict dict;
104 dict["vendor"] = sham::vendor_name(prop.vendor);
105 dict["backend"] = sham::backend_name(prop.backend);
106 dict["type"] = sham::device_type_name(prop.type);
107 dict["name"] = prop.name;
108 dict["platform"] = prop.platform;
109 dict["global_mem_size"] = prop.global_mem_size;
110 dict["global_mem_cache_line_size"] = prop.global_mem_cache_line_size;
111 dict["global_mem_cache_size"] = prop.global_mem_cache_size;
112 dict["local_mem_size"] = prop.local_mem_size;
113 dict["max_compute_units"] = prop.max_compute_units;
114 dict["max_mem_alloc_size_dev"] = prop.max_mem_alloc_size_dev;
115 dict["max_mem_alloc_size_host"] = prop.max_mem_alloc_size_host;
116 dict["mem_base_addr_align"] = prop.mem_base_addr_align;
117 // dict["sub_group_sizes"] = prop.sub_group_sizes;
118 // dict["default_work_group_size"] = prop.default_work_group_size;
119 // dict["pci_address"] = prop.pci_address;
120 // dict["warnings"] = prop.warnings;
121
122 return dict;
123 },
124 R"pbdoc(
125 Get the properties of the compute device
126 )pbdoc");
127
128 m.def(
129 "get_microbench_results",
130 []() {
132 },
133 R"pbdoc(
134 Get the microbench results
135 )pbdoc");
136 }
137} // namespace shamsys::instance
Header file describing a Node Instance.
void init_sycl_mpi(std::string search_key, MPIInitInfo mpi_info)
Start SYCL & MPI.
bool is_initialized()
to check whether the NodeInstance is initialized
void close()
close the NodeInstance Aka : Finalize both MPI & SYCL
Provide information about MPI capabilities.
std::string backend_name(Backend b)
Returns the name of the given backend.
Definition Device.hpp:54
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
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
Definition memory.hpp:110
char ** get_argv()
Get the command line arguments.
Definition cmdopt.cpp:204
int get_argc()
Get the number of command line arguments.
Definition cmdopt.cpp:198
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Definition worldInfo.cpp:40
i32 world_size()
Gives the size of the MPI communicator.
Definition worldInfo.cpp:38
std::string get_process_name()
Get the process name.
Definition mpiInfo.cpp:147
const std::unordered_map< std::string, double > & get_microbench_results()
Get the microbench results.
Pybind11 include and definitions.
Struct containing MPI Init informations Usage.
void Barrier(MPI_Comm comm)
MPI wrapper for MPI_Barrier.
Definition wrapper.cpp:194