From e1a0420ac0605ac5e0a8e548f5d9bf12edb50008 Mon Sep 17 00:00:00 2001 From: Deepak Mewar Date: Mon, 18 Mar 2024 04:49:17 -0400 Subject: [PATCH] Updated README with esmi sample code Change-Id: I50de7926fd76757e5810e8c531bcb6f5770ff454 [ROCm/amdsmi commit: a3407090c3eaa339a53d8a9cac9f8d51d04337ed] --- projects/amdsmi/README.md | 63 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/projects/amdsmi/README.md b/projects/amdsmi/README.md index e50ac965a2..bd25e588b7 100755 --- a/projects/amdsmi/README.md +++ b/projects/amdsmi/README.md @@ -108,7 +108,7 @@ The only required AMD-SMI call for any program that wants to use AMD-SMI is the When AMD-SMI is no longer being used, `amdsmi_shut_down()` should be called. This provides a way to do any releasing of resources that AMD-SMI may have held. -A simple "Hello World" type program that displays the temperature of detected devices would look like this: +1) A simple "Hello World" type program that displays the temperature of detected devices would look like this: ```c++ #include @@ -184,6 +184,67 @@ int main() { } ``` +2) A sample program that displays the power of detected cpus would look like this: + +```c++ +#include +#include +#include "amd_smi/amdsmi.h" + +int main(int argc, char **argv) { + amdsmi_status_t ret; + uint32_t socket_count = 0; + + // Initialize amdsmi for AMD CPUs + ret = amdsmi_init(AMDSMI_INIT_AMD_CPUS); + + ret = amdsmi_get_socket_handles(&socket_count, nullptr); + + // Allocate the memory for the sockets + std::vector sockets(socket_count); + + // Get the sockets of the system + ret = amdsmi_get_socket_handles(&socket_count, &sockets[0]); + + std::cout << "Total Socket: " << socket_count << std::endl; + + // For each socket, get cpus + for (uint32_t i = 0; i < socket_count; i++) { + uint32_t cpu_count = 0; + + // Set processor type as AMD_CPU + processor_type_t processor_type = AMD_CPU; + ret = amdsmi_get_processor_handles_by_type(sockets[i], processor_type, nullptr, &cpu_count); + + // Allocate the memory for the cpus + std::vector plist(cpu_count); + + // Get the cpus for each socket + ret = amdsmi_get_processor_handles_by_type(sockets[i], processor_type, &plist[0], &cpu_count); + + for (uint32_t index = 0; index < plist.size(); index++) { + uint32_t socket_power; + std::cout<<"CPU "<(socket_power)/1000<