Created
August 8, 2018 18:19
-
-
Save ctcyang/e94ae9ad598619ec4a76612191109295 to your computer and use it in GitHub Desktop.
Test for GPU hardware link topology
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cuda.h> | |
#include <cuda_runtime_api.h> | |
#include <iostream> | |
#define NUM_GPUS 8 | |
void PrintMatrix( const std::string& str, int matrix[NUM_GPUS*NUM_GPUS], | |
int num_rows, int num_cols ) { | |
std::cout << str << ":\n"; | |
int count = 0; | |
for (int row = 0; row < num_rows; ++row) { | |
for (int col = 0; col < num_cols; ++col) { | |
std::cout << matrix[count++] << " "; | |
} | |
std::cout << std::endl; | |
} | |
} | |
int main(int argc, char** argv) { | |
int perf[NUM_GPUS*NUM_GPUS]; | |
cudaDeviceP2PAttr attr; | |
attr = cudaDevP2PAttrPerformanceRank; | |
for (int row = 0; row < NUM_GPUS; ++row) { | |
for (int col = 0; col < NUM_GPUS; ++col) { | |
if (row==col) { | |
perf[row*NUM_GPUS+col] = 0; | |
} else { | |
cudaDeviceGetP2PAttribute( &perf[row*NUM_GPUS+col], attr, row, col ); | |
perf[row*NUM_GPUS+col]++; | |
} | |
} | |
} | |
PrintMatrix( "perf", perf, NUM_GPUS, NUM_GPUS ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment