turn 1114.9s turn · 14.9s LLM · 0.0s tools
reasoning
**Exploring code template creation**
I'm thinking about creating a code template for indices from 0 to 15. Compiling each profile could be expensive, so I’m wondering if I should run a disassemble, but actually, that might not be necessary. I could create a function that chooses based on some heuristics for the indices. It might be interesting to consider running profiles in parallel, as that could help avoid GPU contention. I need to profile and test indices 1 and 2.
call → profile_kernel
callprofile_kernel
{
"kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\nIDX=1\ncpp_src=r'''\n#include <torch/extension.h>\nat::Tensor matmul_at_b(at::Tensor A, at::Tensor B);\n'''\ncuda_src=r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda_runtime.h>\n#include <cublasLt.h>\n#define IDX 1\nstatic cublasLtHandle_t h=nullptr; static void* ws=nullptr; static size_t wsSize=64*1024*1024; static cublasLtMatmulDesc_t op=nullptr; static cublasLtMatrixLayout_t ad=nullptr,bd=nullptr,cd=nullptr; static cublasLtMatmulAlgo_t algo; static bool init=false;\nat::Tensor matmul_at_b(at::Tensor A, at::Tensor B){int K=A.size(0),M=A.size(1),N=B.size(1);auto C=at::empty({M,N},A.options()); if(!h){cublasLtCreate(&h);cudaMalloc(&ws,wsSize);} if(!init){cublasLtMatmulDescCreate(&op,CUBLAS_COMPUTE_32F_FAST_TF32,CUDA_R_32F); cublasOperation_t ta=CUBLAS_OP_N,tb=CUBLAS_OP_T; cublasLtMatmulDescSetAttribute(op,CUBLASLT_MATMUL_DESC_TRANSA,&ta,sizeof(ta)); cublasLtMatmulDescSetAttribute(op,CUBLASLT_MATMUL_DESC_TRANSB,&tb,sizeof(tb)); cublasLtMatrixLayoutCreate(&ad,CUDA_R_32F,N,K,N); cublasLtMatrixLayoutCreate(&bd,CUDA_R_32F,M,K,M); cublasLtMatrixLayoutCreate(&cd,CUDA_R_32F,N,M,N); cublasLtMatmulPreference_t pref; cublasLtMatmulPreferenceCreate(&pref); cublasLtMatmulPreferenceSetAttribute(pref,CUBLASLT_MATMUL_PREF_MAX_WORKSPACE_BYTES,&wsSize,sizeof(wsSize)); cublasLtMatmulHeuristicResult_t heur[32]; int ret=0; auto hs=cublasLtMatmulAlgoGetHeuristic(h,op,ad,bd,cd,cd,pref,32,heur,&ret); TORCH_CHECK(hs==CUBLAS_STATUS_SUCCESS&&ret>IDX,\"heur fail\"); algo=heur[IDX].algo; cublasLtMatmulPreferenceDestroy(pref); init=true;} float alpha=1,beta=0; auto st=cublasLtMatmul(h,op,&alpha,B.data_ptr<float>(),ad,A.data_ptr<float>(),bd,&beta,C.data_ptr<float>(),cd,C.data_ptr<float>(),cd,&algo,ws,wsSize,at::cuda::getCurrentCUDAStream()); TORCH_CHECK(st==CUBLAS_STATUS_SUCCESS,\"lt fail\"); return C;}\n'''\n_ext=load_inline(name='matmul_lt_idx1',cpp_sources=cpp_src,cuda_sources=cuda_src,functions=['matmul_at_b'],extra_cuda_cflags=['-O3'],extra_cflags=['-O3'],with_cuda=True,verbose=False)\nclass ModelNew(nn.Module):\n def __init__(self): super().__init__()\n def forward(self,A,B): return _ext.matmul_at_b(A,B)\n"
}
call → profile_kernel
callprofile_kernel
{
"kernel_code": "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\ncpp_src=r'''\n#include <torch/extension.h>\nat::Tensor matmul_at_b(at::Tensor A, at::Tensor B);\n'''\ncuda_src=r'''\n#include <torch/extension.h>\n#include <ATen/cuda/CUDAContext.h>\n#include <cuda_runtime.h>\n#include <cublasLt.h>\n#define IDX 2\nstatic cublasLtHandle_t h=nullptr; static void* ws=nullptr; static size_t wsSize=64*1024*1024; static cublasLtMatmulDesc_t op=nullptr; static cublasLtMatrixLayout_t ad=nullptr,bd=nullptr,cd=nullptr; static cublasLtMatmulAlgo_t algo; static bool init=false;\nat::Tensor matmul_at_b(at::Tensor A, at::Tensor B){int K=A.size(0),M=A.size(1),N=B.size(1);auto C=at::empty({M,N},A.options()); if(!h){cublasLtCreate(&h);cudaMalloc(&ws,wsSize);} if(!init){cublasLtMatmulDescCreate(&op,CUBLAS_COMPUTE_32F_FAST_TF32,CUDA_R_32F); cublasOperation_t ta=CUBLAS_OP_N,tb=CUBLAS_OP_T; cublasLtMatmulDescSetAttribute(op,CUBLASLT_MATMUL_DESC_TRANSA,&ta,sizeof(ta)); cublasLtMatmulDescSetAttribute(op,CUBLASLT_MATMUL_DESC_TRANSB,&tb,sizeof(tb)); cublasLtMatrixLayoutCreate(&ad,CUDA_R_32F,N,K,N); cublasLtMatrixLayoutCreate(&bd,CUDA_R_32F,M,K,M); cublasLtMatrixLayoutCreate(&cd,CUDA_R_32F,N,M,N); cublasLtMatmulPreference_t pref; cublasLtMatmulPreferenceCreate(&pref); cublasLtMatmulPreferenceSetAttribute(pref,CUBLASLT_MATMUL_PREF_MAX_WORKSPACE_BYTES,&wsSize,sizeof(wsSize)); cublasLtMatmulHeuristicResult_t heur[32]; int ret=0; auto hs=cublasLtMatmulAlgoGetHeuristic(h,op,ad,bd,cd,cd,pref,32,heur,&ret); TORCH_CHECK(hs==CUBLAS_STATUS_SUCCESS&&ret>IDX,\"heur fail\"); algo=heur[IDX].algo; cublasLtMatmulPreferenceDestroy(pref); init=true;} float alpha=1,beta=0; auto st=cublasLtMatmul(h,op,&alpha,B.data_ptr<float>(),ad,A.data_ptr<float>(),bd,&beta,C.data_ptr<float>(),cd,C.data_ptr<float>(),cd,&algo,ws,wsSize,at::cuda::getCurrentCUDAStream()); TORCH_CHECK(st==CUBLAS_STATUS_SUCCESS,\"lt fail\"); return C;}\n'''\n_ext=load_inline(name='matmul_lt_idx2',cpp_sources=cpp_src,cuda_sources=cuda_src,functions=['matmul_at_b'],extra_cuda_cflags=['-O3'],extra_cflags=['-O3'],with_cuda=True,verbose=False)\nclass ModelNew(nn.Module):\n def __init__(self): super().__init__()\n def forward(self,A,B): return _ext.matmul_at_b(A,B)\n"
}
result ← profile_kernel (ok)
okprofile_kernel
profile_kernel PASSED: profiling complete.
=== Kernel Profile Summary ===
--- Kernel Breakdown (by GPU time) ---
#1: aten::empty 376.0μs (100%) calls=1
--- Timing ---
GPU time: 523.84 μs [↓1.6μs ok]
--- Memory Bandwidth ---
DRAM BW: 585.1/3350 GB/s (17.5%) [↑0.5% ok]
read=544.6 write=40.5 GB/s
Hit rates: L2=69.7%
--- Compute Throughput ---
Dominant pipe: tensor-core util=56.4% [↑0.0% ok]
Pipe util: FMA=7.9%, Tensor=56.4%
--- Roofline Analysis ---
Ridge point (tensor-core): 295.22 FLOPs/byte
Classification: COMPUTE-BOUND
--- Occupancy ---
Achieved: 17.9%
Eligible warps/cycle: 0.53
WARNING: <1 eligible warp/cycle = latency-bound, needs more parallelism
Launch: regs/thread=168, smem/blk=232448B, block=384, grid=132
--- Memory Access Quality ---
Global ld coalescing: 0.00 sectors/req (perfect)
--- Warp Stall Reasons (% of issue cycles) ---
long_scoreboard 269.3% ####################
short_scoreboard 108.6% ####################
mio_throttle 1.9%
--- Optimization Hints ---
-> 269% stalls: global memory latency (waiting for DRAM/L2). Try shared-memory tiling, prefetching, or reducing working set.
-> Low occupancy (18%) limited by registers (168/thread), shared memory (232448B/block). Consider __launch_bounds__ or reducing register pressure.
--- Delta vs Previous Iteration ---
GPU time: 525.41→523.84μs (↓1.57) ok
DRAM BW%: 16.94→17.47% (↑0.53) ok
Compute%: 56.33→56.36% (↑0.03) ok
L2 hit%: 76.91→69.68% (↓7.23) REGRESSED
result ← profile_kernel (ok)
okprofile_kernel
profile_kernel PASSED: profiling complete.
=== Kernel Profile Summary ===
--- Kernel Breakdown (by GPU time) ---
#1: aten::empty 354.0μs (100%) calls=1
--- Timing ---
GPU time: 524.38 μs [↑0.5μs REGRESSED]
--- Memory Bandwidth ---
DRAM BW: 568.7/3350 GB/s (17.0%) [↓0.5% REGRESSED]
read=528.1 write=40.7 GB/s
Hit rates: L2=73.6%
--- Compute Throughput ---
Dominant pipe: tensor-core util=56.2% [↓0.1% REGRESSED]
Pipe util: FMA=7.9%, Tensor=56.2%
--- Roofline Analysis ---
Ridge point (tensor-core): 295.22 FLOPs/byte
Classification: COMPUTE-BOUND
--- Occupancy ---
Achieved: 17.9%
Eligible warps/cycle: 0.54
WARNING: <1 eligible warp/cycle = latency-bound, needs more parallelism
Launch: regs/thread=168, smem/blk=232448B, block=384, grid=132
--- Memory Access Quality ---
Global ld coalescing: 0.00 sectors/req (perfect)
--- Warp Stall Reasons (% of issue cycles) ---
long_scoreboard 260.6% ####################
short_scoreboard 113.4% ####################
mio_throttle 1.6%
--- Optimization Hints ---
-> 261% stalls: global memory latency (waiting for DRAM/L2). Try shared-memory tiling, prefetching, or reducing working set.
-> Low occupancy (18%) limited by registers (168/thread), shared memory (232448B/block). Consider __launch_bounds__ or reducing register pressure.
--- Delta vs Previous Iteration ---
GPU time: 523.84→524.38μs (↑0.54) REGRESSED
DRAM BW%: 17.47→16.98% (↓0.49) REGRESSED
Compute%: 56.36→56.24% (↓0.12) REGRESSED
L2 hit%: 69.68→73.64% (↑3.96) ok