-
Notifications
You must be signed in to change notification settings - Fork 1
/
hello_nompi.cpp
executable file
·120 lines (93 loc) · 3.69 KB
/
hello_nompi.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
113
114
115
116
117
118
119
120
/**********************************************************
"Hello World"-type program to test different srun layouts.
Original Written by Tom Papatheodore
Adapted to remove MPI by Alexis Espinosa:
Note: MPI has been removed but NOT all informative comments
in relation to MPI & MPI-ranks were updated
**********************************************************/
#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>
#include <unistd.h> //To use gethostname
// 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=1;
//MPI_Comm_size(MPI_COMM_WORLD, &size);
int rank=0;
//MPI_Comm_rank(MPI_COMM_WORLD, &rank);
//char name[MPI_MAX_PROCESSOR_NAME];
char name[HOST_NAME_MAX];
int resultlength;
//MPI_Get_processor_name(name, &resultlength);
resultlength = gethostname(name, HOST_NAME_MAX);
// 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",
printf("MAIN %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 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 - RT_GPU_ID %s - GPU_ID %s - Bus_ID %s\n",
printf("MAIN %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;
}