chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
2 / 43
4.7%
Branches:
0 / 16
0.0%
Functions:
1 / 3
33.3%

device/cuda/adapters.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #include "chrono_batch_render/device/cuda/device.h"
3
4 #include <algorithm>
5
6 #include <fmt/format.h>
7
8 #include "chrono_batch_render/device/compute/compute.h"
9
10 namespace chrono::batch_render::device::cuda {
11 namespace {
12
13 ✗ int Attribute(const Api& cuda, CUdevice device, CUdevice_attribute attribute) {
14 ✗ int value = 0;
15 ✗ cuda.Check(cuda.cuDeviceGetAttribute(&value, attribute, device), "cuDeviceGetAttribute");
16 ✗ return value;
17 }
18
19 ✗ AdapterInfo Describe(const Api& cuda, int ordinal) {
20 ✗ CUdevice device = 0;
21 ✗ cuda.Check(cuda.cuDeviceGet(&device, ordinal), "cuDeviceGet");
22
23 ✗ char name[256] = {};
24 ✗ cuda.Check(cuda.cuDeviceGetName(name, int(sizeof(name)), device), "cuDeviceGetName");
25 ✗ CUuuid uuid{};
26 ✗ cuda.Check(cuda.cuDeviceGetUuid(&uuid, device), "cuDeviceGetUuid");
27 ✗ size_t memory = 0;
28 ✗ cuda.Check(cuda.cuDeviceTotalMem(&memory, device), "cuDeviceTotalMem");
29
30 ✗ compute::ComputeDevice reported = {
31 .backend = Backend::Cuda,
32 ✗ .ordinal = uint32_t(ordinal),
33 ✗ .name = name,
34 .memory = memory,
35 ✗ .integrated = Attribute(cuda, device, CU_DEVICE_ATTRIBUTE_INTEGRATED) != 0,
36 ✗ .warpSize = uint32_t(Attribute(cuda, device, CU_DEVICE_ATTRIBUTE_WARP_SIZE)),
37 ✗ .maxThreads = uint32_t(Attribute(cuda, device, CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK)),
38
0/3
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✗ Branch 8 not taken.
✗ .textures = true};
39 ✗ std::copy(std::begin(uuid.bytes), std::end(uuid.bytes), reported.uuid.begin());
40
0/1
✗ Branch 1 not taken.
✗ AdapterInfo adapter = compute::DescribeCompute(reported);
41
42
0/1
✗ Branch 1 not taken.
✗ const Version capability{Attribute(cuda, device, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR),
43
0/1
✗ Branch 1 not taken.
✗ Attribute(cuda, device, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR)};
44
0/1
✗ Branch 1 not taken.
✗ adapter.architecture = fmt::format("sm_{}{}", capability.major, capability.minor);
45 ✗ adapter.apiVersion = cuda.driverVersion;
46 ✗ adapter.driverVersion = cuda.driverVersion;
47
48
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if (capability < kMinimumComputeCapability) {
49 ✗ adapter.unsupported =
50
0/1
✗ Branch 1 not taken.
✗ fmt::format("compute capability is {}; Chrono Batch Render needs {} or later",
51
0/2
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✗ capability.ToString(), kMinimumComputeCapability.ToString());
52 }
53 ✗ return adapter;
54 ✗ }
55
56 }
57
58 28 std::vector<AdapterInfo> ListAdapters() {
59 28 const Api& cuda = GetApi();
60 ✗ int count = 0;
61 ✗ cuda.Check(cuda.cuDeviceGetCount(&count), "cuDeviceGetCount");
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 ordinal = 0; ordinal < count; ++ordinal) {
65
0/1
✗ Branch 1 not taken.
✗ adapters.push_back(Describe(cuda, ordinal));
66 }
67 ✗ return adapters;
68 ✗ }
69
70 }
71