How could I use cuda block shared memory in the self-defined operator?
まだ誰も着手していません。
評価
- 難易度
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pytorch/extension-cpp のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
pytorch/extension-cpp#100 · コメント 5 件 ·
-
Deprecation warningオープン
難易度 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 日以内に返信