siboehm/SGEMM_CUDA (19 files):
siboehm_sgemm.cu, siboehm_runner.cu, siboehm_runner.cuh, siboehm_kernels.cuh
siboehm_cuBLAS_sgemm.cu, siboehm_simplest_kernel.cu, siboehm_CMakeLists.txt
siboehm_{1_naive..12_kernel_double_buffering}.cuh
wangzyon/NVIDIA_SGEMM_PRACTICE (12 files):
wangzyon_sgemm.cu, wangzyon_utils.cu, wangzyon_utils.cuh, wangzyon_kernel.cuh
wangzyon_CMakeLists.txt, wangzyon_kernel_{1..7}.cuh
edtallison/sgemm-cuda (19 files):
edtallison_sgemm.cu, edtallison_runner.cu, edtallison_runner.cuh
edtallison_kernels.cuh, edtallison_cuBLAS_sgemm.cu, edtallison_simplest_kernel.cu
edtallison_CMakeLists.txt, edtallison_{01_naive..12_kernel_double_buffering}.cuh
cat_files/ total: 25 → 75 files
47 lines
1.1 KiB
Plaintext
47 lines
1.1 KiB
Plaintext
#include <cuda_runtime.h>
|
|
#include <iostream>
|
|
#include <vector>
|
|
|
|
__global__ void kernel(uint *A, uint *B, int row) {
|
|
auto x = threadIdx.x / 4;
|
|
auto y = threadIdx.x % 4;
|
|
A[x * row + y] = x;
|
|
B[x * row + y] = y;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
uint *Xs, *Ys;
|
|
uint *Xs_d, *Ys_d;
|
|
|
|
uint SIZE = 4;
|
|
|
|
Xs = (uint *)malloc(SIZE * SIZE * sizeof(uint));
|
|
Ys = (uint *)malloc(SIZE * SIZE * sizeof(uint));
|
|
|
|
cudaMalloc((void **)&Xs_d, SIZE * SIZE * sizeof(uint));
|
|
cudaMalloc((void **)&Ys_d, SIZE * SIZE * sizeof(uint));
|
|
|
|
dim3 grid_size(1, 1, 1);
|
|
dim3 block_size(4 * 4);
|
|
|
|
kernel<<<grid_size, block_size>>>(Xs_d, Ys_d, 4);
|
|
|
|
cudaMemcpy(Xs, Xs_d, SIZE * SIZE * sizeof(uint), cudaMemcpyDeviceToHost);
|
|
cudaMemcpy(Ys, Ys_d, SIZE * SIZE * sizeof(uint), cudaMemcpyDeviceToHost);
|
|
|
|
cudaDeviceSynchronize();
|
|
|
|
for (int row = 0; row < SIZE; ++row) {
|
|
for (int col = 0; col < SIZE; ++col) {
|
|
std::cout << "[" << Xs[row * SIZE + col] << "|" << Ys[row * SIZE + col]
|
|
<< "] ";
|
|
}
|
|
std::cout << "\n";
|
|
}
|
|
|
|
cudaFree(Xs_d);
|
|
cudaFree(Ys_d);
|
|
free(Xs);
|
|
free(Ys);
|
|
}
|