Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions code/nvidia/gemm_bench.cu
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <sstream>

#include <cuda.h>
#include <cuda_fp16.h>
#include <cublas_v2.h>
#include <curand.h>

Expand Down Expand Up @@ -54,7 +55,7 @@ Supported precision types:
For Maxwell GPUS:
float for training and inference

For Pascal GPUS:
For Pascal/Volta GPUS:
float, half for training
float, half, int8 for inference

Expand Down Expand Up @@ -85,11 +86,22 @@ int time_gemm(Tensor<T1> A, Tensor<T1> B, Tensor<T2> C, bool a_t, bool b_t, cubl
cudaDataType_t compute_type = CUDA_R_32F;
cublasGemmAlgo_t algo;

if (std::is_same<T1, uint16_t>::value) {
if (std::is_same<T1, __half>::value) {
A_type = CUDA_R_16F;
B_type = CUDA_R_16F;
C_type = CUDA_R_16F;
compute_type = CUDA_R_16F;
}

if (std::is_same<T2, float>::value) {
C_type = CUDA_R_32F;
compute_type = CUDA_R_32F;
} else if (std::is_same<T2, __half>::value) {
C_type = CUDA_R_16F;
compute_type = CUDA_R_16F;
} else if (std::is_same<T2, int>::value) {
compute_type = CUDA_R_32I;
} else {
std::cerr << "Unsuported T2 (output) type" << std::endl;
exit(1);
}

if (std::is_same<T1, uint8_t>::value) {
Expand Down Expand Up @@ -219,8 +231,7 @@ int main(int argc, char **argv) {

if (status != CUBLAS_STATUS_SUCCESS) {
std::cout << "CUBLAS math mode failed" << std::endl;
}

} else std::cout << "CUBALS_TENSOR_OP_MATH ON" << std::endl;


curandGenerator_t curand_gen;
Expand Down Expand Up @@ -290,18 +301,24 @@ int main(int argc, char **argv) {
if (!skip_kernel)
time_ms = time_gemm<uint8_t, int>(a, b, c, a_t, b_t, cublas_handle);
} else if (precision == "half") {
auto a = rand<uint16_t>({a_t ? k : m, a_t ? m : k}, curand_gen);
auto b = rand<uint16_t>({b_t ? n : k, b_t ? k : n}, curand_gen);
auto c = zeros<uint16_t>({m, n});
auto a = rand<__half>({a_t ? k : m, a_t ? m : k}, curand_gen);
auto b = rand<__half>({b_t ? n : k, b_t ? k : n}, curand_gen);
auto c = zeros<__half>({m, n});
std::cout << std::setw(13) << precision;
time_ms = time_gemm<uint16_t, uint16_t>(a, b, c, a_t, b_t, cublas_handle);
time_ms = time_gemm<__half, __half>(a, b, c, a_t, b_t, cublas_handle);
} else if (precision == "float") {
auto a = rand<float>({a_t ? k : m, a_t ? m : k}, curand_gen);
auto b = rand<float>({b_t ? n : k, b_t ? k : n}, curand_gen);
auto c = zeros<float>({m, n});
std::cout << std::setw(13) << precision;
time_ms = time_gemm<float, float>(a, b, c, a_t, b_t, cublas_handle);
} else {
} else if (precision == "mixed") { // f16 x f16 to f32
auto a = rand<__half>({a_t ? k : m, a_t ? m : k}, curand_gen);
auto b = rand<__half>({b_t ? n : k, b_t ? k : n}, curand_gen);
auto c = zeros<float>({m, n});
std::cout << std::setw(13) << precision;
time_ms = time_gemm<__half, float>(a, b, c, a_t, b_t, cublas_handle);
} else {
throw std::runtime_error(ss.str());
}
#else
Expand Down