Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatible with g++ 12 #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ else()
target_compile_definitions(${PROJECT_NAME} PRIVATE NO_DRAM_TELEMETRY)
endif()

find_package(fmt CONFIG REQUIRED)

target_link_libraries(${PROJECT_NAME} PRIVATE
CUDA::nvml
reflect::reflect
range-v3::range-v3
fmt
)

target_include_directories(${PROJECT_NAME} PRIVATE
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ SecureBoot disabled

## Dependencies
- libpci-dev
- libfmt-dev
```
sudo apt install libpci-dev -y
sudo apt install libpci-dev libfmt-dev -y
```

## Supported GPUs
Expand Down
20 changes: 10 additions & 10 deletions nv_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <thread>
#include <unordered_map>
#include <cstdlib>
#include <format>
#include <fmt/core.h>

#include <stdlib.h>
#include <errno.h>
Expand Down Expand Up @@ -334,7 +334,7 @@ int main() {
if (device.mapped_addr == MAP_FAILED)
{
device.mapped_addr = NULL;
std::cerr << std::format("Memory mapping failed for pci={:x}:{:x}:{:x}\n", device.pci_info.bus, device.pci_info.device, device.pci_info.domain);
std::cerr << fmt::format("Memory mapping failed for pci={:x}:{:x}:{:x}\n", device.pci_info.bus, device.pci_info.device, device.pci_info.domain);
std::cerr << "Did you enable iomem=relaxed? Are you root?\n";
return 1;
}
Expand Down Expand Up @@ -376,31 +376,31 @@ int main() {
if (field) {
using field_T = std::remove_cvref_t<decltype(*field)>;
std::string value;
if constexpr (std::is_same_v<field_T, std::string>) value = std::format("\"{}\"", escape_string(*field));
if constexpr (std::is_same_v<field_T, std::string>) value = fmt::format("\"{}\"", escape_string(*field));
else if constexpr (std::is_same_v<field_T, bool>) value = (*field ? "true" : "false");
else if constexpr (std::is_same_v<field_T, uint64_t>) value = std::format("{}u", *field);
else value = std::format("{}", *field);
else if constexpr (std::is_same_v<field_T, uint64_t>) value = fmt::format("{}u", *field);
else value = fmt::format("{}", *field);

metrics.push_back(std::format("{}={}", name, value));
metrics.push_back(fmt::format("{}={}", name, value));
} else {
errors.push_back(std::format("{} ({})", name, reflect::enum_name(field.error())));
errors.push_back(fmt::format("{} ({})", name, reflect::enum_name(field.error())));
}
}, gpu);
}, gpu);

#ifndef NO_DRAM_TELEMETRY
if (device.mapped_addr != NULL && device.mapped_addr != MAP_FAILED) {
void *virt_addr = (uint8_t *)device.mapped_addr + (device.phys_addr - device.base_offset);
uint32_t read_result = *((uint32_t *)virt_addr);
uint32_t temp = ((read_result & 0x00000fff) / 0x20);
metrics.push_back(std::format("temperature_memory={}", temp));
metrics.push_back(fmt::format("temperature_memory={}", temp));
}
#endif

if (!errors.empty()) {
auto error_str = errors
| ranges::views::join(",")
| ranges::to<std::string>();
metrics.push_back(std::format("errors=\"{}\"", escape_string(error_str)));
metrics.push_back(fmt::format("errors=\"{}\"", escape_string(error_str)));
}

std::cout << "nv_export"
Expand Down