How could I use cuda block shared memory in the self-defined operator?
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 半天
- 新手友好度
- 45/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 領域
- devtools, performance
研究方向
The problem is in main.cu: the templated kernel TestForward declares extern __shared__ scalar_t sdata[], and it is instantiated for float and c10::Half, which clashes with the same symbol. Start from the errors on line 21 and the dispatch in test_forward_cuda. Done when the extension builds through setup.py for both scalar types and the kernel writes to shared memory without the redeclaration warning.
由索引模型根據 Issue 內容生成。
描述
I am working on ubuntu16.04 with pytorch1.3 installed from conda.
My cuda version is 10.1.243 and cudnn version is 7.
I have 8 t4 gpus on my server and the gcc version is the default 5.4.
When submitting a bug report, please include the following information (where relevant):
The simplified version of my code main.cu is like this:
#include <torch/extension.h>
#include <ATen/ATen.h>
#include <ATen/cuda/CUDAContext.h>
#include <THC/THC.h>
#include <THC/THCAtomics.cuh>
#include <THC/THCDeviceUtils.cuh>
#include <cuda.h>
#include <cuda_runtime.h>
#include <cfloat>
// kernel function for forward and backward
template<typename scalar_t>
__global__ void TestForward() {
int tid = threadIdx.x + (blockIdx.x * gridDim.y + blockIdx.y) * blockDim.x;
int stride = blockDim.x * blockDim.y * gridDim.x;
extern __shared__ scalar_t sdata[];
sdata[threadIdx.x] = 0; // numer
sdata[threadIdx.x + blockDim.x] = 0; // denor
__syncthreads();
}
// cuda forward and backward
at::Tensor test_forward_cuda() {
dim3 grid(4096);
dim3 block(512);
auto ret = at::empty(1024);
AT_DISPATCH_FLOATING_TYPES_AND_HALF(ret.scalar_type(), "forward", [&] {
TestForward<scalar_t><<<grid, block, 4096, at::cuda::getCurrentCUDAStream()>>>();
});
return ret;
}
// python inferface
at::Tensor test_forward() {
return test_forward_cuda();
}
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("test_forward", &test_forward, "forward");
}
and the setup.py is like this:
from setuptools import setup, Extension
from torch.utils import cpp_extension
setup(
name='pytorch',
ext_modules=[
cpp_extension.CUDAExtension(
'main_cpp',
['main.cu']),
],
cmdclass={'build_ext': cpp_extension.BuildExtension}
)
I compiled it with command python setup.py install. And the error message is like this:
main.cu(21): error: declaration is incompatible with previous "sdata"
(21): here
detected during instantiation of "void TestForward<scalar_t>() [with scalar_t=float]"
(34): here
main.cu(21): warning: a host variable("sdata") redeclared with __shared__
detected during instantiation of "void TestForward<scalar_t>() [with scalar_t=float]"
(34): here
main.cu(21): warning: a host variable("sdata") redeclared with __shared__
detected during instantiation of "void TestForward<scalar_t>() [with scalar_t=c10::Half]"
(34): here
1 error detected in the compilation of "/tmp/tmpxft_00022124_00000000-6_main.cpp1.ii".
What is the cause of this and how could I cope with this problem please ?
- 主要語言
- Python
- 星號
- 1.2k
- 分支
- 250
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
pytorch/extension-cpp 的其他 Issue
-
難度 1/5 1 小時以內 新手友好度 68/100
pytorch/extension-cpp#100 · 5 則留言 ·
-
難度 1/5 1 小時以內 新手友好度 78/100
pytorch/extension-cpp#82 ·
-
難度 4/5 3-5 天 新手友好度 45/100
pytorch/extension-cpp#124 ·
-
難度 3/5 1-2 天 新手友好度 35/100
pytorch/extension-cpp#123 ·
-
難度 4/5 1-2 天 新手友好度 12/100
pytorch/extension-cpp#121 · 3 則留言 ·
查看 pytorch/extension-cpp 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
hermes hooks doctor smoke test never checks the hook exit code — a crashing hook (exit=1) renders ✓ "ran clean" and "All shell hooks look healthy"可能已有人在做 @cestercian 今天認領。 未關閉comp/cli P2 type/bug
難度 2/5 1-3 小時 新手友好度 75/100
NousResearch/hermes-agent#162259 · 1 則留言 ·
維護者通常 1 天內回覆
-
upstream update
難度 2/5 1-3 小時 新手友好度 72/100
conan-io/conan-center-index#31597 ·
維護者通常 1 天內回覆
-
bug enhancement
難度 1/5 1 小時以內 新手友好度 90/100
AOSSIE-Org/PictoPy#1802 · 2 則留言 ·
維護者通常 3 天內回覆
-
community-request
難度 2/5 1-3 小時 新手友好度 78/100
NVIDIA-NeMo/Run#727 ·
維護者通常 1 天內回覆