Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix gen rand data and use of cublasHgemm #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
18 changes: 9 additions & 9 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ float testF16F16GemmMaxError(

srand(time(0));
for (int i = 0; i < M * K; i++)
h_a[i] = (T)(rand() / 65504 - 65504/2);
h_a[i] = (T)((rand() % 200 - 100) * 0.01); // -1 ~ 1
for (int i = 0; i < K * N; i++)
h_b[i] = (T)(rand() / 65504 - 65504/2);
h_b[i] = (T)((rand() % 200 - 100) * 0.01);

cpuF16F16Gemm(h_a, h_b, h_c, M, N, K);

Expand Down Expand Up @@ -148,9 +148,9 @@ float testF16F16GemmMaxError_V2(

srand(time(0));
for (int i = 0; i < M * K; i++)
h_a[i] = (T)(rand() / 65504 - 65504/2);
h_a[i] = (T)((rand() % 200 - 100) * 0.01); // -1 ~ 1
for (int i = 0; i < K * N; i++)
h_b[i] = (T)(rand() / 65504 - 65504/2);
h_b[i] = (T)((rand() % 200 - 100) * 0.01);

cublasHandle_t handle;
cublasCreate(&handle);
Expand All @@ -160,12 +160,12 @@ float testF16F16GemmMaxError_V2(
cudaMemcpy(d_a, h_a, size_a, cudaMemcpyHostToDevice);
cudaMemcpy(d_b, h_b, size_b, cudaMemcpyHostToDevice);

cublasHgemm(handle, CUBLAS_OP_T, CUBLAS_OP_N, M, N, K,
&alpha, (half *)d_a, K, (half *)d_b, K,
&beta, (half *)d_c_ref, N);
// cublasHgemm(handle, CUBLAS_OP_T, CUBLAS_OP_N, N, M, K,
// &alpha, (half *)d_b, K, (half *)d_a, K,
// cublasHgemm(handle, CUBLAS_OP_T, CUBLAS_OP_N, M, N, K,
// &alpha, (half *)d_a, K, (half *)d_b, K,
// &beta, (half *)d_c_ref, N);
cublasHgemm(handle, CUBLAS_OP_T, CUBLAS_OP_N, N, M, K,
&alpha, (half *)d_b, K, (half *)d_a, K,
&beta, (half *)d_c_ref, N);
// 上面两种调用 cublas 方式等同
gpuF16F16Gemm(d_a, d_b, d_c, M, N, K);

Expand Down