TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
19 / 21
90.5%
Branches:
8 / 18
44.4%
Functions:
1 / 2
50.0%

python/src/gpu.cpp
Line Branch Exec Source
1 #include "bindings.h"
2 #include "common.h"
3
4 #include "terraingen/gpu/backend.h"
5
6 #include <string>
7
8 namespace terraingen::python {
9
10 44 void BindGpu(nb::module_& m) {
11 88 nb::enum_<Backend>(m, "Backend", "Where evaluation runs.")
12 44 .value("AUTO", Backend::Auto, "A GPU when one is available, otherwise the CPU.")
13 44 .value("CPU", Backend::Cpu, "The reference C++ implementation.")
14 44 .value("VULKAN", Backend::Vulkan, "Vulkan compute on the device TERRAINGEN_DEVICE selects.")
15 44 .value("GPU", Backend::Gpu,
16 "The best GPU backend available, whichever it is; an error when there is none.")
17 44 .value("CUDA", Backend::Cuda,
18 "CUDA on the first NVIDIA device, through the driver opened at run time.")
19 .value("METAL", Backend::Metal, "Metal on the system's default device; Apple only.");
20 44 nb::class_<BackendStatus>(m, "BackendStatus",
21 "Whether a backend can run here, on which device, or why not.")
22 44 .def_ro("backend", &BackendStatus::backend)
23 44 .def_ro("available", &BackendStatus::available)
24 44 .def_ro("device", &BackendStatus::device)
25 88 .def_ro("reason", &BackendStatus::reason)
26 44 .def("__repr__", [](const BackendStatus& s) {
27
0/5
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ return "BackendStatus(" + std::string(BackendName(s.backend)) + ", " +
28
0/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✗ Branch 6 not taken.
✗ Branch 9 not taken.
✗ (s.available ? "available on " + s.device : "unavailable: " + s.reason) + ")";
29 });
30
1/1
✓ Branch 1 taken 44 times.
44 m.def("backends", &Backends,
31 "The status of the CPU, Vulkan, CUDA and Metal backends, in that order; each GPU library "
32 "is opened on first use, never at import.");
33
2/2
✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
44 m.def("backend_named", &BackendNamed, "name"_a,
34 "The backend named 'auto', 'cpu', 'gpu', 'vulkan', 'cuda' or 'metal', or None.");
35
1/1
✓ Branch 1 taken 44 times.
44 m.def("default_backend", &DefaultBackend,
36 "The default backend evaluation uses unless told otherwise: what set_default_backend "
37 "set, otherwise TERRAINGEN_BACKEND, otherwise CPU.");
38
2/2
✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
44 m.def("set_default_backend", &SetDefaultBackend, "backend"_a,
39 "Sets the default backend, overriding TERRAINGEN_BACKEND.");
40
2/2
✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
44 m.def("resolve_backend", &ResolveBackend, "backend"_a,
41 "The backend `backend` resolves to: GPU becomes the best GPU backend available (METAL, "
42 "then CUDA, then VULKAN), AUTO the same or CPU when there is none. Raises RuntimeError "
43 "for a GPU backend that is unavailable.");
44 44 }
45
46 } // namespace terraingen::python
47