chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
2 / 43
4.7%
Branches:
0 / 18
0.0%
Functions:
1 / 4
25.0%

device/hip/adapters.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #include "chrono_batch_render/device/hip/device.h"
3
4 #include <algorithm>
5 #include <array>
6 #include <cstring>
7
8 #include "chrono_batch_render/device/compute/compute.h"
9
10 namespace chrono::batch_render::device::hip {
11 namespace {
12
13 ✗ int Attribute(const Api& hip, int device, hipDeviceAttribute_t attribute) {
14 ✗ int value = 0;
15 ✗ hip.Check(hip.hipDeviceGetAttribute(&value, attribute, device), "hipDeviceGetAttribute");
16 ✗ return value;
17 }
18
19 ✗ std::string ArchitectureName(const Api& hip, int device) {
20 ✗ alignas(8) std::array<char, kDevicePropertiesR0600Bytes> properties{};
21 ✗ hip.Check(hip.hipGetDevicePropertiesR0600(properties.data(), device),
22 "hipGetDevicePropertiesR0600");
23 ✗ const char* name = properties.data() + kDevicePropertiesR0600ArchNameOffset;
24 ✗ const std::string_view full(name, strnlen(name, 256));
25 ✗ return std::string(full.substr(0, full.find(':')));
26 }
27
28 ✗ AdapterInfo Describe(const Api& hip, int device) {
29 ✗ char name[256] = {};
30 ✗ hip.Check(hip.hipDeviceGetName(name, int(sizeof(name)), device), "hipDeviceGetName");
31 ✗ hipUUID uuid{};
32 ✗ hip.Check(hip.hipDeviceGetUuid(&uuid, device), "hipDeviceGetUuid");
33 ✗ size_t memory = 0;
34 ✗ hip.Check(hip.hipDeviceTotalMem(&memory, device), "hipDeviceTotalMem");
35 ✗ const std::string architecture = ArchitectureName(hip, device);
36
37 ✗ compute::ComputeDevice reported = {
38 .backend = Backend::Hip,
39 ✗ .ordinal = uint32_t(device),
40
0/1
✗ Branch 1 not taken.
✗ .name = name,
41 .memory = memory,
42 ✗ .integrated = Attribute(hip, device, hipDeviceAttributeIntegrated) != 0,
43 ✗ .warpSize = uint32_t(Attribute(hip, device, hipDeviceAttributeWarpSize)),
44 ✗ .maxThreads = uint32_t(Attribute(hip, device, hipDeviceAttributeMaxThreadsPerBlock)),
45 ✗ .textures = Attribute(hip, device, hipDeviceAttributeImageSupport) != 0 &&
46
0/11
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ !architecture.starts_with("gfx94") && !architecture.starts_with("gfx95")};
47 ✗ std::copy(std::begin(uuid.bytes), std::end(uuid.bytes), reported.uuid.begin());
48
0/1
✗ Branch 1 not taken.
✗ AdapterInfo adapter = compute::DescribeCompute(reported);
49
50
0/1
✗ Branch 1 not taken.
✗ adapter.architecture = architecture;
51 ✗ adapter.apiVersion = hip.runtimeVersion;
52 ✗ adapter.driverVersion = hip.driverVersion;
53 ✗ return adapter;
54 ✗ }
55
56 }
57
58 28 std::vector<AdapterInfo> ListAdapters() {
59 28 const Api& hip = GetApi();
60 ✗ int count = 0;
61 ✗ hip.Check(hip.hipGetDeviceCount(&count), "hipGetDeviceCount");
62 ✗ std::vector<AdapterInfo> adapters;
63
0/1
✗ Branch 1 not taken.
✗ adapters.reserve(count);
64
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ for (int device = 0; device < count; ++device) {
65
0/1
✗ Branch 1 not taken.
✗ adapters.push_back(Describe(hip, device));
66 }
67 ✗ return adapters;
68 ✗ }
69
70 }
71