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 | ✗ | .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 | ✗ | !architecture.starts_with("gfx94") && !architecture.starts_with("gfx95")}; | |
| 47 | ✗ | std::copy(std::begin(uuid.bytes), std::end(uuid.bytes), reported.uuid.begin()); | |
| 48 | ✗ | AdapterInfo adapter = compute::DescribeCompute(reported); | |
| 49 | |||
| 50 | ✗ | 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 | ✗ | adapters.reserve(count); | |
| 64 | ✗ | for (int device = 0; device < count; ++device) { | |
| 65 | ✗ | adapters.push_back(Describe(hip, device)); | |
| 66 | } | ||
| 67 | ✗ | return adapters; | |
| 68 | ✗ | } | |
| 69 | |||
| 70 | } | ||
| 71 |