chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
0 / 28
0.0%
Branches:
0 / 14
0.0%
Functions:
0 / 3, 2 excl
0.0%

device/compute/runtime_compiler.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <cstddef>
5 #include <filesystem>
6 #include <initializer_list>
7 #include <memory>
8 #include <mutex>
9 #include <span>
10 #include <string>
11 #include <string_view>
12 #include <unordered_map>
13
14 #include "chrono_batch_render/util/disk_cache.h"
15 #include "chrono_batch_render/util/library.h"
16 #include "chrono_batch_render/util/version.h"
17
18 namespace chrono::batch_render::device::compute {
19
20 struct SourceHeader {
21 const char* name;
22 std::string_view text;
23 };
24
25 ✗ struct RuntimeCompiler {
26 using Program = struct CompilerProgram*;
27
28 std::string name;
29 std::string library;
30 Version version;
31
32 int (*getVersion)(int* major, int* minor) = nullptr;
33 const char* (*getErrorString)(int result) = nullptr;
34 int (*createProgram)(Program* program, const char* source, const char* name, int headers,
35 const char* const* sources, const char* const* names) = nullptr;
36 int (*destroyProgram)(Program* program) = nullptr;
37 int (*compileProgram)(Program program, int count, const char* const* options) = nullptr;
38 int (*getLogSize)(Program program, size_t* bytes) = nullptr;
39 int (*getLog)(Program program, char* log) = nullptr;
40 int (*getCodeSize)(Program program, size_t* bytes) = nullptr;
41 int (*getCode)(Program program, char* code) = nullptr;
42
43 std::string Compile(std::string_view source, std::span<const SourceHeader> headers,
44 std::span<const std::string> options, std::string_view what) const;
45
46 ✗ struct Compiled {
47 std::string code;
48 bool cached = false;
49 };
50
51 Compiled CompileCached(std::string_view source, std::span<const SourceHeader> headers,
52 std::span<const std::string> options, std::string_view what,
53 const DiskCache& cache) const;
54 };
55
56 Loaded<RuntimeCompiler> LoadRuntimeCompiler(std::string_view name, std::string_view prefix,
57 std::string_view code,
58 std::initializer_list<const char*> names,
59 std::initializer_list<const char*> paths,
60 Version minimum,
61 const std::filesystem::path& beside = {});
62
63
0/2
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✗ class ModuleCache {
64 public:
65 ✗ template <class Load> std::shared_ptr<void> Find(const std::string& binary, Load load) {
66 ✗ const std::lock_guard lock(m_mutex);
67
0/2
std::shared_ptr<void> chrono::batch_render::device::compute::ModuleCache::Find<chrono::batch_render::device::compute::ComputeKernel<chrono::batch_render::device::cuda::Traits>::Load(chrono::batch_render::device::KernelCode const&, chrono::batch_render::DiskCache const&, chrono::batch_render::DeviceGlobals const&)::{lambda()#1}>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, chrono::batch_render::device::compute::ComputeKernel<chrono::batch_render::device::cuda::Traits>::Load(chrono::batch_render::device::KernelCode const&, chrono::batch_render::DiskCache const&, chrono::batch_render::DeviceGlobals const&)::{lambda()#1}):
✗ Branch 1 not taken.
std::shared_ptr<void> chrono::batch_render::device::compute::ModuleCache::Find<chrono::batch_render::device::compute::ComputeKernel<chrono::batch_render::device::hip::Traits>::Load(chrono::batch_render::device::KernelCode const&, chrono::batch_render::DiskCache const&, chrono::batch_render::DeviceGlobals const&)::{lambda()#1}>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, chrono::batch_render::device::compute::ComputeKernel<chrono::batch_render::device::hip::Traits>::Load(chrono::batch_render::device::KernelCode const&, chrono::batch_render::DiskCache const&, chrono::batch_render::DeviceGlobals const&)::{lambda()#1}):
✗ Branch 1 not taken.
✗ std::shared_ptr<void>& module = m_modules[binary];
68
0/4
std::shared_ptr<void> chrono::batch_render::device::compute::ModuleCache::Find<chrono::batch_render::device::compute::ComputeKernel<chrono::batch_render::device::cuda::Traits>::Load(chrono::batch_render::device::KernelCode const&, chrono::batch_render::DiskCache const&, chrono::batch_render::DeviceGlobals const&)::{lambda()#1}>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, chrono::batch_render::device::compute::ComputeKernel<chrono::batch_render::device::cuda::Traits>::Load(chrono::batch_render::device::KernelCode const&, chrono::batch_render::DiskCache const&, chrono::batch_render::DeviceGlobals const&)::{lambda()#1}):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
std::shared_ptr<void> chrono::batch_render::device::compute::ModuleCache::Find<chrono::batch_render::device::compute::ComputeKernel<chrono::batch_render::device::hip::Traits>::Load(chrono::batch_render::device::KernelCode const&, chrono::batch_render::DiskCache const&, chrono::batch_render::DeviceGlobals const&)::{lambda()#1}>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, chrono::batch_render::device::compute::ComputeKernel<chrono::batch_render::device::hip::Traits>::Load(chrono::batch_render::device::KernelCode const&, chrono::batch_render::DiskCache const&, chrono::batch_render::DeviceGlobals const&)::{lambda()#1}):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if (!module) {
69 try {
70
0/6
std::shared_ptr<void> chrono::batch_render::device::compute::ModuleCache::Find<chrono::batch_render::device::compute::ComputeKernel<chrono::batch_render::device::cuda::Traits>::Load(chrono::batch_render::device::KernelCode const&, chrono::batch_render::DiskCache const&, chrono::batch_render::DeviceGlobals const&)::{lambda()#1}>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, chrono::batch_render::device::compute::ComputeKernel<chrono::batch_render::device::cuda::Traits>::Load(chrono::batch_render::device::KernelCode const&, chrono::batch_render::DiskCache const&, chrono::batch_render::DeviceGlobals const&)::{lambda()#1}):
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
std::shared_ptr<void> chrono::batch_render::device::compute::ModuleCache::Find<chrono::batch_render::device::compute::ComputeKernel<chrono::batch_render::device::hip::Traits>::Load(chrono::batch_render::device::KernelCode const&, chrono::batch_render::DiskCache const&, chrono::batch_render::DeviceGlobals const&)::{lambda()#1}>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, chrono::batch_render::device::compute::ComputeKernel<chrono::batch_render::device::hip::Traits>::Load(chrono::batch_render::device::KernelCode const&, chrono::batch_render::DiskCache const&, chrono::batch_render::DeviceGlobals const&)::{lambda()#1}):
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ module = load();
71 ✗ } catch (...) {
72 ✗ m_modules.erase(binary);
73 ✗ throw;
74 }
75 }
76 ✗ return module;
77 ✗ }
78
79 ✗ void Clear() {
80 ✗ const std::lock_guard lock(m_mutex);
81 ✗ m_modules.clear();
82 ✗ }
83
84 private:
85 std::mutex m_mutex;
86 std::unordered_map<std::string, std::shared_ptr<void>> m_modules;
87 };
88
89 }
90