forked from baidu-research/DeepBench
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.svail.baidu.com:baidu-research/DeepBe…
…nch-internal into volta_updates
- Loading branch information
Showing
18 changed files
with
276 additions
and
84 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
SUBDIRS= nvidia osu_allreduce | ||
SUBDIRS= nvidia osu_allreduce baidu_allreduce | ||
|
||
subdirs: $(SUBDIRS) | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
CC=mpic++ | ||
NVCC=nvcc | ||
ARCH?=sm_52 | ||
|
||
CUDA_PATH?=/usr/local/cuda | ||
CUDA_LIB64=$(CUDA_PATH)/lib64 | ||
MPI_PATH?=/usr/local/openmpi | ||
BAIDU_ALLREDUCE_PATH?=/local/baidu-allreduce | ||
BIN_DIR?=bin | ||
MKDIR=mkdir -p | ||
#BLAS | ||
BLAS_LIBRARY?=cublas | ||
BLAS_PATH?=$(CUDA_LIB64) | ||
#CONV | ||
KERNELS_DIR=../kernels/ | ||
COMMA=, | ||
NVCC_ARCH_ARGS=$(foreach a,$(subst $(COMMA), ,$(ARCH)),--generate-code arch=$(patsubst sm_%,compute_%,$(a)),code=$(a)) | ||
|
||
.PHONY=all ring_all_reduce clean | ||
|
||
ring_all_reduce: | ||
$(MKDIR) $(BIN_DIR) | ||
$(MPI_PATH)/bin/$(CC) -c -std=c++11 -I $(MPI_PATH)/include -I $(BAIDU_ALLREDUCE_PATH) -I $(CUDA_PATH)/include -I $(KERNELS_DIR) -DOMPI_SKIP_MPICXX= ring_all_reduce_mpi.cpp -o $(BIN_DIR)/ring_all_reduce_mpi.o | ||
$(CUDA_PATH)/bin/$(NVCC) -c -std=c++11 -I $(MPI_PATH)/include -I $(BAIDU_ALLREDUCE_PATH) -I $(CUDA_PATH)/include -DOMPI_SKIP_MPICXX= $(BAIDU_ALLREDUCE_PATH)/collectives.cu -o $(BIN_DIR)/collectives.o | ||
$(MPI_PATH)/bin/$(CC) -o $(BIN_DIR)/ring_all_reduce $(BIN_DIR)/ring_all_reduce_mpi.o $(BIN_DIR)/collectives.o -L$(CUDA_PATH)/lib64 -L$(MPI_PATH)/lib -lcudart -lmpi -DOMPI_SKIP_MPICXX= | ||
|
||
clean: | ||
rm -rf $(BIN_DIR) | ||
|
||
rebuild: clean all |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include "collectives.h" | ||
|
||
#include <iomanip> | ||
#include <sstream> | ||
|
||
#include <mpi.h> | ||
#include <cuda_runtime.h> | ||
|
||
#include <stdexcept> | ||
#include <iostream> | ||
#include <vector> | ||
#include <algorithm> | ||
#include <stdio.h> | ||
|
||
#include "all_reduce_problems.h" | ||
#include <chrono> | ||
|
||
|
||
int main(int argc, char** argv, char** envp) { | ||
|
||
int mpi_size, mpi_rank, mpi_local_rank; | ||
|
||
char* env_str = std::getenv("OMPI_COMM_WORLD_LOCAL_RANK"); | ||
if(env_str == NULL) { | ||
env_str = std::getenv("SLURM_LOCALID"); | ||
} | ||
|
||
mpi_local_rank = std::stoi(std::string(env_str)); | ||
|
||
InitCollectives(mpi_local_rank); | ||
|
||
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); | ||
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); | ||
MPI_Barrier(MPI_COMM_WORLD); | ||
|
||
int64_t* sizes = all_reduce_kernels_size; | ||
int64_t* numRepeats = all_reduce_kernels_repeat; | ||
|
||
if (mpi_rank == 0) { | ||
std::cout << " Ring AllReduce " << std::endl; | ||
std::cout << " Num Ranks: " << mpi_size << std::endl; | ||
|
||
std::cout << std::setfill('-') << std::setw(100) << "-" << std::endl; | ||
std::cout << std::setfill(' '); | ||
std::cout << " # of floats bytes transferred Avg Time (msec) Max Time (msec)" << std::endl; | ||
|
||
std::cout << std::setfill('-') << std::setw(100) << "-" << std::endl; | ||
std::cout << std::setfill(' '); | ||
} | ||
|
||
cudaError_t err; | ||
for (int kernel_pos = 0; kernel_pos < _NUMBER_OF_KERNELS_; kernel_pos++) { | ||
auto t_size = sizes[kernel_pos]; | ||
|
||
float* cpu_data = new float[t_size]; | ||
std::fill_n(cpu_data, t_size, 1.0f); | ||
|
||
float* data; | ||
err = cudaMalloc(&data, sizeof(float) * t_size); | ||
if(err != cudaSuccess) { throw std::runtime_error("cudaMalloc failed!"); } | ||
|
||
err = cudaMemcpy(data, cpu_data, sizeof(float) * t_size, cudaMemcpyHostToDevice); | ||
if(err != cudaSuccess) { throw std::runtime_error("cudaMemcpy failed!"); } | ||
|
||
float time_sum = 0; | ||
for (int i = 0; i < numRepeats[kernel_pos]; i++) { | ||
|
||
float* output; | ||
|
||
auto start = std::chrono::steady_clock::now(); | ||
RingAllreduce(data, t_size, &output); | ||
auto end = std::chrono::steady_clock::now(); | ||
time_sum += std::chrono::duration<double, std::milli>(end - start).count(); | ||
|
||
err = cudaFree(output); | ||
if(err != cudaSuccess) { throw std::runtime_error("cudaFree failed!"); } | ||
} | ||
|
||
float time = static_cast<float>(time_sum / numRepeats[kernel_pos]); | ||
|
||
float max_time, avg_time; | ||
MPI_Reduce(&time, &max_time, 1, MPI_FLOAT, MPI_MAX, 0, MPI_COMM_WORLD); | ||
MPI_Reduce(&time, &avg_time, 1, MPI_FLOAT, MPI_SUM, 0, MPI_COMM_WORLD); | ||
MPI_Barrier(MPI_COMM_WORLD); | ||
|
||
if (mpi_rank == 0) { | ||
avg_time = avg_time/mpi_size; | ||
std::cout << std::setw(15) << t_size << std::setw(15) << t_size * 4 << std::setw(20) << avg_time << std::setw(20) << max_time << std::endl; | ||
} | ||
|
||
err = cudaFree(data); | ||
if(err != cudaSuccess) { throw std::runtime_error("cudaFree failed!"); } | ||
|
||
delete [] cpu_data; | ||
} | ||
|
||
MPI_Finalize(); | ||
|
||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef _ALL_REDUCE_KERNELS_ | ||
#define _ALL_REDUCE_KERNELS_ | ||
|
||
|
||
#define _NUMBER_OF_KERNELS_ 7 | ||
|
||
int64_t all_reduce_kernels_size[] = {100000, 3097600, 4194304, 6553600, 16777217, 38360000, 64500000}; | ||
int64_t all_reduce_kernels_repeat[] = {10000, 10000, 10000, 10000, 1000, 1000, 1000}; | ||
|
||
#endif |
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
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
Oops, something went wrong.