Hello !
I’am studying now to control multi GPU by CUDA.
But I have no idea how to control them.
I reference this site (https://github.com/zchee/cuda-sample/blob/master/0_Simple/simpleMultiGPU/simpleMultiGPU.cu), but there is a codes that used for.
Instead, that codes inspired me, so I use cuda + mpi to initialize device ID by rank and execute at the same time.
But My codes used only one GPU… :(
How can I control GPUs parallely ?
Here is my code
#include <stdio.h>
#include <curand.h>
#include <mpi.h>
#define XBLOCKSIZE 10
#define XGRIDSIZE 10
int main(int argc, char** argv) {
int mpi_error, rank, numtasks;
mpi_error = MPI_Init(&argc, &argv);
if(mpi_error != MPI_SUCCESS) {
printf("MPI error has occured.\n");
return 0;
}
MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
//rank 0 print problem size
if(rank == 0)
printf("<<<%d,%d>>>\n", XGRIDSIZE, XBLOCKSIZE);
int num_of_gpus;
cudaGetDeviceCount(&num_of_gpus);
printf("number of gpus : %d\n", num_of_gpus);
printf("My rank : %d\n", rank);
if(numtasks > num_of_gpus){
printf("Too many process than number of gpus\n");
return 1;
}
int devID = rank;
cudaError_t error;
cudaDeviceProp deviceProp;
error = cudaGetDevice(&devID);
if(error != cudaSuccess){
printf("cudaGetDevice returned error %s\n", cudaGetErrorString(error));
}
error = cudaGetDeviceProperties(&deviceProp, devID);
if(error != cudaSuccess){
printf("cudaGetDeviceProperties returned error %s\n", cudaGetErrorString(error));
}
else{
printf("GPU BUS ID : %d\n", deviceProp.pciBusID);
printf("GPU Device ID : %d\n", deviceProp.pciDeviceID);
}
MPI_Finalize();
return 0;
}
Results :
<<<10,10>>>
number of gpus : 2
My rank : 0
number of gpus : 2
My rank : 1
GPU BUS ID : 24
GPU Device ID : 0
GPU BUS ID : 24
GPU Device ID : 0