-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhello_jobstep.cpp
executable file
·112 lines (85 loc) · 3.23 KB
/
hello_jobstep.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**********************************************************
"Hello World"-type program to test different srun layouts.
Written by Tom Papatheodore
**********************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <iomanip>
#include <string.h>
#include <mpi.h>
#include <sched.h>
#include <hip/hip_runtime.h>
#include <omp.h>
// Macro for checking errors in HIP API calls
#define hipErrorCheck(call) \
do{ \
hipError_t hipErr = call; \
if(hipSuccess != hipErr){ \
printf("HIP Error - %s:%d: '%s'\n", __FILE__, __LINE__, hipGetErrorString(hipErr)); \
exit(0); \
} \
}while(0)
int main(int argc, char *argv[]){
MPI_Init(&argc, &argv);
int size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
char name[MPI_MAX_PROCESSOR_NAME];
int resultlength;
MPI_Get_processor_name(name, &resultlength);
// If ROCR_VISIBLE_DEVICES is set, capture visible GPUs
const char* gpu_id_list;
const char* rocr_visible_devices = getenv("ROCR_VISIBLE_DEVICES");
if(rocr_visible_devices == NULL){
gpu_id_list = "N/A";
}
else{
gpu_id_list = rocr_visible_devices;
}
// Find how many GPUs HIP runtime says are available
int num_devices = 0;
hipErrorCheck( hipGetDeviceCount(&num_devices) );
int hwthread;
int thread_id = 0;
if(num_devices == 0){
#pragma omp parallel default(shared) private(hwthread, thread_id)
{
thread_id = omp_get_thread_num();
hwthread = sched_getcpu();
printf("MPI %03d - OMP %03d - HWT %03d - Node %s\n",
rank, thread_id, hwthread, name);
}
}
else{
char busid[64];
std::string busid_list = "";
std::string rt_gpu_id_list = "";
// Loop over the GPUs available to each MPI rank
for(int i=0; i<num_devices; i++){
hipErrorCheck( hipSetDevice(i) );
// Get the PCIBusId for each GPU and use it to query for UUID
hipErrorCheck( hipDeviceGetPCIBusId(busid, 64, i) );
// Concatenate per-MPIrank GPU info into strings for print
if(i > 0) rt_gpu_id_list.append(",");
rt_gpu_id_list.append(std::to_string(i));
std::string temp_busid(busid);
if(i > 0) busid_list.append(",");
busid_list.append(temp_busid.substr(5,2));
}
#pragma omp parallel default(shared) private(hwthread, thread_id)
{
#pragma omp critical
{
thread_id = omp_get_thread_num();
hwthread = sched_getcpu();
printf("MPI %03d - OMP %03d - HWT %03d - Node %s - RunTime_GPU_ID %s - ROCR_VISIBLE_GPU_ID %s - GPU_Bus_ID %s\n",
rank, thread_id, hwthread, name, rt_gpu_id_list.c_str(), gpu_id_list, busid_list.c_str());
}
}
}
MPI_Finalize();
return 0;
}