Skip to content

Commit 9c7398a

Browse files
authored
Feature: output the hardware information in both the command line and the running_scf log (#3127)
* feature: output the hardware information in both the command line and the running_scf log * fix mpi output * add rocm device info output
1 parent 8b98951 commit 9c7398a

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

source/module_esolver/esolver.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "esolver.h"
2-
2+
#include "module_psi/kernels/device.h"
33
#include "esolver_ks_pw.h"
44
#include "esolver_sdft_pw.h"
55
#ifdef __LCAO
@@ -81,6 +81,18 @@ namespace ModuleESolver
8181
}
8282

8383
GlobalV::ofs_running << " The esolver type has been set to : " << esolver_type << std::endl;
84+
auto device_info = GlobalV::device_flag;
85+
for (char &c : device_info) {
86+
if (std::islower(c)) {
87+
c = std::toupper(c);
88+
}
89+
}
90+
if (GlobalV::MY_RANK == 0) {
91+
std::cout << " RUNNING WITH DEVICE : " << device_info << " / "
92+
<< psi::device::get_device_info(GlobalV::device_flag) << std::endl;
93+
}
94+
GlobalV::ofs_running << "\n RUNNING WITH DEVICE : " << device_info << " / "
95+
<< psi::device::get_device_info(GlobalV::device_flag) << std::endl;
8496
return esolver_type;
8597
}
8698

source/module_psi/kernels/device.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,5 +609,46 @@ int get_device_kpar(const int& kpar) {
609609
return kpar;
610610
}
611611

612+
std::string get_device_info(std::string device_flag)
613+
{
614+
std::string device_info = "Unknown";
615+
616+
#if defined(__CUDA)
617+
if (device_flag == "gpu") {
618+
int dev = 0;
619+
cudaDeviceProp deviceProp;
620+
cudaGetDeviceProperties(&deviceProp, dev);
621+
device_info = deviceProp.name;
622+
}
623+
#elif defined(__ROCM)
624+
if (device_flag == "gpu") {
625+
int dev = 0;
626+
hipDeviceProp_t deviceProp;
627+
hipGetDeviceProperties(&deviceProp, dev);
628+
device_info = deviceProp.name;
629+
}
630+
#endif
631+
if (device_flag == "cpu") {
632+
std::ifstream cpuinfo("/proc/cpuinfo");
633+
std::string line = "", cpu_name = "";
634+
635+
while (std::getline(cpuinfo, line)) {
636+
if (line.find("model name") != std::string::npos) {
637+
// Extract the CPU name from the line
638+
size_t colonPos = line.find(":");
639+
if (colonPos != std::string::npos) {
640+
cpu_name = line.substr(colonPos + 2); // Skip the colon and space
641+
break; // Stop after the first match
642+
}
643+
}
644+
}
645+
if (cpu_name != "") {
646+
device_info = cpu_name;
647+
}
648+
cpuinfo.close();
649+
}
650+
return device_info;
651+
}
652+
612653
} // end of namespace device
613654
} // end of namespace psi

source/module_psi/kernels/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ template<typename Device> void print_device_info (const Device* dev, std::ofstre
3434

3535
template<typename Device> void record_device_memory (const Device* dev, std::ofstream& ofs_device, std::string str, size_t size) {return;}
3636

37+
std::string get_device_info(std::string device_flag);
38+
3739
int get_device_kpar(const int& kpar);
3840
std::string get_device_flag(const std::string& device, const std::string& ks_solver, const std::string& basis_type);
3941

0 commit comments

Comments
 (0)