-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGPU_peak_perf_test.cu
More file actions
93 lines (70 loc) · 2.28 KB
/
Copy pathGPU_peak_perf_test.cu
File metadata and controls
93 lines (70 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <torch/types.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <hip/hip_runtime.h>
#include <hip/hip_fp16.h>
#include <hip/hip_bfloat16.h>
#include <hip/amd_detail/amd_hip_bf16.h>
#include <hip/amd_detail/amd_hip_fp16.h>
#include <rocwmma/rocwmma.hpp>
#include <torch/extension.h>
using rocwmma::accumulator;
using rocwmma::col_major;
using rocwmma::matrix_a;
using rocwmma::matrix_b;
using rocwmma::row_major;
using rocwmma::bfloat16_t;
using rocwmma::float16_t;
using rocwmma::float32_t;
const int ROCWMMA_M = 16;
const int ROCWMMA_N = 16;
const int ROCWMMA_K = 16;
const int WAVE_SIZE = 32;
#define ComputeType float16_t
#define AT_PTR_TYPE at::Half
#define TORCH_DTYPE torch::kFloat16
typedef _Float16 fp16_frag __attribute__((ext_vector_type(16)));
typedef float fp32_frag __attribute__((ext_vector_type(8)));
__global__ void gemm_kernel(
float *wb
)
{
fp16_frag fragA;
fp16_frag fragB;
fp32_frag fragACC = {};
fragA[0] = blockIdx.x;
fragB[0] = (threadIdx.x);
//#pragma unroll 200
for (int i = 0; i < 100000; i++)
{
fragACC = __builtin_amdgcn_wmma_f32_16x16x16_f16_w32(fragA, fragB, fragACC);
fragACC = __builtin_amdgcn_wmma_f32_16x16x16_f16_w32(fragA, fragB, fragACC);
fragACC = __builtin_amdgcn_wmma_f32_16x16x16_f16_w32(fragA, fragB, fragACC);
fragACC = __builtin_amdgcn_wmma_f32_16x16x16_f16_w32(fragA, fragB, fragACC);
fragACC = __builtin_amdgcn_wmma_f32_16x16x16_f16_w32(fragA, fragB, fragACC);
}
wb[0] = fragACC[0];
// asm volatile("s_sleep 0");
}
torch::Tensor forward(int n_block, int n_waves
)
{
cudaError_t err = cudaGetLastError();
auto optD = torch::TensorOptions().dtype(torch::kFloat32).device(torch::kCUDA);
auto D = torch::zeros({16}, optD);
auto gridDim = dim3(n_block, 1, 1);
auto blockDim = dim3(WAVE_SIZE , n_waves);
gemm_kernel<<<gridDim, blockDim, 0>>>(
(float *)D.data_ptr()
);
err = cudaGetLastError();
if (err != hipSuccess)
{
printf("=============== Backward Kernel Launch Failed !!! =============\r\n");
printf("CUDA Error: %s\n", cudaGetErrorString(err));
}
return D;
}
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("forward", torch::wrap_pybind_function(forward), "forward");
}