under test, not sure no errors
This commit is contained in:
29
upstream_ref/sgemm_cuda/1_naive.cuh
Normal file
29
upstream_ref/sgemm_cuda/1_naive.cuh
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cublas_v2.h>
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
/*
|
||||
|
||||
Matrix sizes:
|
||||
MxK * KxN = MxN
|
||||
|
||||
*/
|
||||
|
||||
__global__ void sgemm_naive(int M, int N, int K, float alpha, const float *A,
|
||||
const float *B, float beta, float *C) {
|
||||
const uint x = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
const uint y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
|
||||
// if statement is necessary to make things work under tile quantization
|
||||
if (x < M && y < N) {
|
||||
float tmp = 0.0;
|
||||
for (int i = 0; i < K; ++i) {
|
||||
tmp += A[x * K + i] * B[i * N + y];
|
||||
}
|
||||
// C = α*(A@B)+β*C
|
||||
C[x * N + y] = alpha * tmp + beta * C[x * N + y];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user