Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
composable_kernel
Commits
84b36bc1
"examples/vscode:/vscode.git/clone" did not exist on "ec953047bc0f4a3542e673f3d463543c02505ca5"
Commit
84b36bc1
authored
Nov 04, 2018
by
Chao Liu
Browse files
sucess cuda run
parent
6a45afba
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
202 additions
and
176 deletions
+202
-176
driver/conv.cu
driver/conv.cu
+57
-77
src/include/constant_direct_convolution.cuh
src/include/constant_direct_convolution.cuh
+116
-72
src/include/constant_tensor_descriptor.cuh
src/include/constant_tensor_descriptor.cuh
+29
-27
No files found.
driver/conv.cu
View file @
84b36bc1
#include <iostream>
#include <iostream>
#include <numeric>
#include <numeric>
#include <initializer_list>
#include <initializer_list>
#include <cstdlib>
#include "nvToolsExt.h"
#include "nvToolsExt.h"
#include "tensor.hpp"
#include "tensor.hpp"
#include "constant_tensor_descriptor.cuh"
#include "constant_tensor_descriptor.cuh"
...
@@ -30,7 +31,10 @@ struct GeneratorTensor
...
@@ -30,7 +31,10 @@ struct GeneratorTensor
template
<
class
...
Is
>
template
<
class
...
Is
>
T
operator
()(
Is
...
is
)
T
operator
()(
Is
...
is
)
{
{
#if 0
#if 1
return
std
::
rand
()
/
RAND_MAX
;
#elif 0
std
::
initializer_list
<
std
::
size_t
>
ls
=
{
static_cast
<
std
::
size_t
>
(
is
)...};
std
::
initializer_list
<
std
::
size_t
>
ls
=
{
static_cast
<
std
::
size_t
>
(
is
)...};
return
std
::
accumulate
(
ls
.
begin
(),
ls
.
end
(),
std
::
size_t
(
0
));
return
std
::
accumulate
(
ls
.
begin
(),
ls
.
end
(),
std
::
size_t
(
0
));
#else
#else
...
@@ -111,53 +115,6 @@ void host_convolution(const Tensor<T>& in, const Tensor<T>& wei, Tensor<T>& out)
...
@@ -111,53 +115,6 @@ void host_convolution(const Tensor<T>& in, const Tensor<T>& wei, Tensor<T>& out)
f_par
(
std
::
thread
::
hardware_concurrency
());
f_par
(
std
::
thread
::
hardware_concurrency
());
}
}
#if 0
template <class T>
void device_convolution(
const Tensor<T>& in, const Tensor<T>& wei, Tensor<T>& out)
{
DeviceTensorDescriptor<4> in_desc_device(in.mDesc);
DeviceTensorDescriptor<4> wei_desc_device(wei.mDesc);
DeviceTensorDescriptor<4> out_desc_device(out.mDesc);
printf("__func__: in_desc_device: {%u %u %u %u}, {%u %u %u %u}\n",
in_desc_device.GetLength(0),
in_desc_device.GetLength(1),
in_desc_device.GetLength(2),
in_desc_device.GetLength(3),
in_desc_device.GetStride(0),
in_desc_device.GetStride(1),
in_desc_device.GetStride(2),
in_desc_device.GetStride(3));
std::size_t data_sz = sizeof(T);
DeviceMem in_device_buf(data_sz * in.mDesc.GetElementSpace());
DeviceMem wei_device_buf(data_sz * wei.mDesc.GetElementSpace());
DeviceMem out_device_buf(data_sz * out.mDesc.GetElementSpace());
int num_thread = std::thread::hardware_concurrency();
out.GenerateTensorValue(GeneratorConstant<float>{0}, num_thread);
in_device_buf.ToDevice(in.mData.data());
wei_device_buf.ToDevice(wei.mData.data());
out_device_buf.ToDevice(out.mData.data());
dim3 block_dim(64, 1, 1);
dim3 grid_dim(1, 1, 1);
gridwise_convolution<T, 3, 3, 4, 4, 2, 2, 1, 1, 8, 8, 1>
<<<grid_dim, block_dim>>>(in_desc_device,
static_cast<T*>(in_device_buf.GetDeviceBuffer()),
wei_desc_device,
static_cast<T*>(wei_device_buf.GetDeviceBuffer()),
out_desc_device,
static_cast<T*>(out_device_buf.GetDeviceBuffer()));
checkCudaErrors(cudaGetLastError());
out_device_buf.FromDevice(out.mData.data());
}
#else
template
<
class
T
,
class
InDesc
,
class
WeiDesc
,
class
OutDesc
>
template
<
class
T
,
class
InDesc
,
class
WeiDesc
,
class
OutDesc
>
void
const_device_convolution
(
void
const_device_convolution
(
InDesc
,
const
Tensor
<
T
>&
in
,
WeiDesc
,
const
Tensor
<
T
>&
wei
,
OutDesc
,
Tensor
<
T
>&
out
)
InDesc
,
const
Tensor
<
T
>&
in
,
WeiDesc
,
const
Tensor
<
T
>&
wei
,
OutDesc
,
Tensor
<
T
>&
out
)
...
@@ -169,36 +126,45 @@ void const_device_convolution(
...
@@ -169,36 +126,45 @@ void const_device_convolution(
int
num_thread
=
std
::
thread
::
hardware_concurrency
();
int
num_thread
=
std
::
thread
::
hardware_concurrency
();
#if 0
out.GenerateTensorValue(GeneratorConstant<float>{0}, num_thread);
out.GenerateTensorValue(GeneratorConstant<float>{0}, num_thread);
#endif
in_device_buf
.
ToDevice
(
in
.
mData
.
data
());
in_device_buf
.
ToDevice
(
in
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
wei
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
wei
.
mData
.
data
());
out_device_buf
.
ToDevice
(
out
.
mData
.
data
());
out_device_buf
.
ToDevice
(
out
.
mData
.
data
());
dim3
block_dim
(
64
,
1
,
1
);
dim3
grid_dim
(
1
,
1
,
1
);
constexpr
auto
I0
=
Index
<
0
>
{};
constexpr
auto
I0
=
Index
<
0
>
{};
constexpr
auto
I1
=
Index
<
1
>
{};
constexpr
auto
I1
=
Index
<
1
>
{};
constexpr
auto
I2
=
Index
<
2
>
{};
constexpr
auto
I2
=
Index
<
2
>
{};
constexpr
auto
I3
=
Index
<
3
>
{};
constexpr
auto
I3
=
Index
<
3
>
{};
constexpr
auto
in_desc
=
InDesc
{};
constexpr
auto
in_desc
=
InDesc
{};
constexpr
auto
wei_desc
=
WeiDesc
{};
constexpr
auto
wei_desc
=
WeiDesc
{};
constexpr
auto
out_desc
=
OutDesc
{};
constexpr
auto
out_desc
=
OutDesc
{};
constexpr
unsigned
NPerBlock
=
1
;
constexpr
unsigned
NPerBlock
=
1
;
constexpr
unsigned
KPerBlock
=
1
;
constexpr
unsigned
KPerBlock
=
1
;
constexpr
unsigned
CPerBlockLoop
=
1
;
constexpr
unsigned
CPerBlockLoop
=
1
;
constexpr
unsigned
OutTileSizeH
=
2
;
constexpr
unsigned
OutTileSizeH
=
2
;
constexpr
unsigned
OutTileSizeW
=
2
;
constexpr
unsigned
OutTileSizeW
=
2
;
constexpr
unsigned
YPerBlock
=
(
out_desc
.
GetLength
(
I2
)
+
OutTileSizeH
-
1
)
/
OutTileSizeH
;
constexpr
unsigned
YPerBlock
=
16
;
constexpr
unsigned
XPerBlock
=
(
out_desc
.
GetLength
(
I3
)
+
OutTileSizeW
-
1
)
/
OutTileSizeW
;
constexpr
unsigned
XPerBlock
=
16
;
constexpr
unsigned
NBlockCopyLen0
=
1
;
constexpr
unsigned
NBlockCopyLen0
=
1
;
constexpr
unsigned
NBlockCopyLen1
=
1
;
constexpr
unsigned
NBlockCopyLen1
=
1
;
constexpr
unsigned
NBlockCopyLen2
=
1
;
constexpr
unsigned
NBlockCopyLen2
=
1
;
constexpr
unsigned
NBlockCopyLen3
=
64
;
constexpr
unsigned
NBlockCopyLen3
=
64
;
constexpr
unsigned
nblock
=
(
out_desc
.
GetLength
(
I0
)
/
NPerBlock
)
*
(
out_desc
.
GetLength
(
I1
)
/
KPerBlock
)
*
(
out_desc
.
GetLength
(
I2
)
/
(
OutTileSizeH
*
YPerBlock
))
*
(
out_desc
.
GetLength
(
I3
)
/
(
OutTileSizeW
*
XPerBlock
));
dim3
block_dim
(
32
);
dim3
grid_dim
(
nblock
);
printf
(
"__func__: nblock %u
\n
"
,
nblock
);
gridwise_convolution
<
T
,
gridwise_convolution
<
T
,
InDesc
,
InDesc
,
WeiDesc
,
WeiDesc
,
...
@@ -224,11 +190,10 @@ void const_device_convolution(
...
@@ -224,11 +190,10 @@ void const_device_convolution(
checkCudaErrors
(
cudaGetLastError
());
checkCudaErrors
(
cudaGetLastError
());
out_device_buf
.
FromDevice
(
out
.
mData
.
data
());
out_device_buf
.
FromDevice
(
out
.
mData
.
data
());
}
}
#endif
int
main
()
int
main
()
{
{
#if
1
#if
0
constexpr unsigned N = 1;
constexpr unsigned N = 1;
constexpr unsigned C = 1;
constexpr unsigned C = 1;
constexpr unsigned HI = 18;
constexpr unsigned HI = 18;
...
@@ -237,21 +202,21 @@ int main()
...
@@ -237,21 +202,21 @@ int main()
constexpr unsigned S = 3;
constexpr unsigned S = 3;
constexpr unsigned R = 3;
constexpr unsigned R = 3;
#elif
1
#elif
1
constexpr
unsigned
N
=
1
;
constexpr
unsigned
N
=
64
;
constexpr
unsigned
C
=
1
;
constexpr
unsigned
C
=
256
;
constexpr
unsigned
HI
=
3
6
;
constexpr
unsigned
HI
=
3
4
;
constexpr
unsigned
WI
=
3
6
;
constexpr
unsigned
WI
=
3
4
;
constexpr
unsigned
K
=
1
;
constexpr
unsigned
K
=
56
;
constexpr
unsigned
S
=
3
;
constexpr
unsigned
S
=
3
;
constexpr
unsigned
R
=
3
;
constexpr
unsigned
R
=
3
;
#elif 0
#elif 0
constexpr
unsigned
N
=
1
;
constexpr
unsigned
N
=
2
;
constexpr
unsigned
C
=
1
;
constexpr
unsigned
C
=
3
;
constexpr
unsigned
HI
=
130
;
constexpr
unsigned
HI
=
130
;
constexpr
unsigned
WI
=
130
;
constexpr
unsigned
WI
=
130
;
constexpr
unsigned
K
=
1
;
constexpr
unsigned
K
=
5
;
constexpr
unsigned
S
=
3
;
constexpr
unsigned
S
=
3
;
constexpr
unsigned
R
=
3
;
constexpr
unsigned
R
=
3
;
#elif 0
#elif 0
constexpr
unsigned
N
=
3
;
constexpr
unsigned
N
=
3
;
constexpr
unsigned
C
=
16
;
constexpr
unsigned
C
=
16
;
...
@@ -278,28 +243,43 @@ int main()
...
@@ -278,28 +243,43 @@ int main()
int
num_thread
=
std
::
thread
::
hardware_concurrency
();
int
num_thread
=
std
::
thread
::
hardware_concurrency
();
#if 0
in.GenerateTensorValue(GeneratorTensor<float>{}, num_thread);
in.GenerateTensorValue(GeneratorTensor<float>{}, num_thread);
wei.GenerateTensorValue(GeneratorTensor<float>{}, num_thread);
wei.GenerateTensorValue(GeneratorTensor<float>{}, num_thread);
#endif
#if 0
host_convolution(in, wei, out_host);
host_convolution(in, wei, out_host);
#endif
#if 0
device_convolution(in, wei, out_device);
#else
const_device_convolution
(
in_desc
,
in
,
wei_desc
,
wei
,
out_desc
,
out_device
);
const_device_convolution
(
in_desc
,
in
,
wei_desc
,
wei
,
out_desc
,
out_device
);
#endif
std
::
cout
<<
__func__
<<
": done"
<<
std
::
endl
;
std
::
cout
<<
__func__
<<
": done"
<<
std
::
endl
;
#if 0
LogRange(std::cout << __func__ << "in : ", in.mData, ",") << std::endl;
LogRange(std::cout << __func__ << "in : ", in.mData, ",") << std::endl;
LogRange(std::cout << __func__ << "wei: ", wei.mData, ",") << std::endl;
LogRange(std::cout << __func__ << "wei: ", wei.mData, ",") << std::endl;
LogRange(std::cout, out_host.mData, ",") << std::endl;
LogRange(std::cout, out_host.mData, ",") << std::endl;
LogRange(std::cout, out_device.mData, ",") << std::endl;
LogRange(std::cout, out_device.mData, ",") << std::endl;
#endif
float
error
=
0
;
#if 0
float error = 0;
float max_diff = 0;
float host_value = 0, device_value = 0;
for(int i = 0; i < out_host.mData.size(); ++i)
for(int i = 0; i < out_host.mData.size(); ++i)
{
{
error += std::abs(out_host.mData[i] - out_device.mData[i]);
error += std::abs(out_host.mData[i] - out_device.mData[i]);
float diff = std::abs(out_host.mData[i] - out_device.mData[i]);
if(max_diff < diff)
{
max_diff = diff;
host_value = out_host.mData[i];
device_value = out_device.mData[i];
}
}
}
std::cout << "error: " << error << std::endl;
std::cout << "error: " << error << std::endl;
std::cout << "max_diff: " << max_diff << ", " << host_value << ", " << device_value
<< std::endl;
#endif
}
}
src/include/constant_direct_convolution.cuh
View file @
84b36bc1
...
@@ -20,11 +20,11 @@ __device__ void blockwise_4d_tensor_op(
...
@@ -20,11 +20,11 @@ __device__ void blockwise_4d_tensor_op(
constexpr
auto
src_desc
=
SrcDesc
{};
constexpr
auto
src_desc
=
SrcDesc
{};
constexpr
auto
dst_desc
=
DstDesc
{};
constexpr
auto
dst_desc
=
DstDesc
{};
#if
1
#if
0
if(threadIdx.x == 0)
if(threadIdx.x == 0)
{
{
print_ConstantTensorDescriptor
(
src_desc
);
print_ConstantTensorDescriptor(src_desc
, "blockwise_4d_tensor_op: src_desc: "
);
print_ConstantTensorDescriptor
(
dst_desc
);
print_ConstantTensorDescriptor(dst_desc
, "blockwise_4d_tensor_op: dst_desc: "
);
}
}
#endif
#endif
...
@@ -99,7 +99,7 @@ __device__ void threadwise_4d_tensor_op(
...
@@ -99,7 +99,7 @@ __device__ void threadwise_4d_tensor_op(
constexpr
auto
src_desc
=
SrcDesc
{};
constexpr
auto
src_desc
=
SrcDesc
{};
constexpr
auto
dst_desc
=
DstDesc
{};
constexpr
auto
dst_desc
=
DstDesc
{};
#if
1
#if
0
if(threadIdx.x == 0)
if(threadIdx.x == 0)
{
{
print_ConstantTensorDescriptor(src_desc);
print_ConstantTensorDescriptor(src_desc);
...
@@ -161,7 +161,7 @@ __device__ void threadwise_direct_convolution(InDesc,
...
@@ -161,7 +161,7 @@ __device__ void threadwise_direct_convolution(InDesc,
constexpr
auto
wei_desc
=
WeiDesc
{};
constexpr
auto
wei_desc
=
WeiDesc
{};
constexpr
auto
out_desc
=
OutDesc
{};
constexpr
auto
out_desc
=
OutDesc
{};
#if
1
#if
0
if(threadIdx.x == 0)
if(threadIdx.x == 0)
{
{
print_ConstantTensorDescriptor(in_desc);
print_ConstantTensorDescriptor(in_desc);
...
@@ -262,7 +262,7 @@ __device__ void blockwise_convolution(InDesc,
...
@@ -262,7 +262,7 @@ __device__ void blockwise_convolution(InDesc,
constexpr
unsigned
InTileSizeH
=
OutTileSizeH
+
S
-
1
;
constexpr
unsigned
InTileSizeH
=
OutTileSizeH
+
S
-
1
;
constexpr
unsigned
InTileSizeW
=
OutTileSizeW
+
R
-
1
;
constexpr
unsigned
InTileSizeW
=
OutTileSizeW
+
R
-
1
;
#if
1
#if
0
if(threadIdx.x == 0)
if(threadIdx.x == 0)
{
{
print_ConstantTensorDescriptor(in_desc);
print_ConstantTensorDescriptor(in_desc);
...
@@ -417,40 +417,43 @@ __global__ void gridwise_convolution(InDesc,
...
@@ -417,40 +417,43 @@ __global__ void gridwise_convolution(InDesc,
constexpr
unsigned
S
=
wei_desc
.
GetLength
(
I2
);
constexpr
unsigned
S
=
wei_desc
.
GetLength
(
I2
);
constexpr
unsigned
R
=
wei_desc
.
GetLength
(
I3
);
constexpr
unsigned
R
=
wei_desc
.
GetLength
(
I3
);
#if 1
constexpr
unsigned
HoPerBlock
=
OutTileSizeH
*
YPerBlock
;
if
(
threadIdx
.
x
==
0
)
constexpr
unsigned
WoPerBlock
=
OutTileSizeW
*
XPerBlock
;
{
print_ConstantTensorDescriptor
(
in_desc
);
constexpr
unsigned
HiPerBlock
=
YPerBlock
*
OutTileSizeH
+
S
-
1
;
print_ConstantTensorDescriptor
(
wei_desc
);
constexpr
unsigned
WiPerBlock
=
XPerBlock
*
OutTileSizeW
+
R
-
1
;
print_ConstantTensorDescriptor
(
out_desc
);
}
#endif
constexpr
unsigned
NBlockWork
=
(
out_desc
.
GetLength
(
I0
)
+
NPerBlock
-
1
)
/
NPerBlock
;
constexpr
unsigned
NBlockWork
=
(
out_desc
.
GetLength
(
I0
)
+
NPerBlock
-
1
)
/
NPerBlock
;
constexpr
unsigned
KBlockWork
=
(
out_desc
.
GetLength
(
I1
)
+
KPerBlock
-
1
)
/
KPerBlock
;
constexpr
unsigned
KBlockWork
=
(
out_desc
.
GetLength
(
I1
)
+
KPerBlock
-
1
)
/
KPerBlock
;
constexpr
unsigned
YBlockWork
=
(
out_desc
.
GetLength
(
I2
)
+
Y
PerBlock
-
1
)
/
Y
PerBlock
;
constexpr
unsigned
YBlockWork
=
(
out_desc
.
GetLength
(
I2
)
+
Ho
PerBlock
-
1
)
/
Ho
PerBlock
;
constexpr
unsigned
XBlockWork
=
(
out_desc
.
GetLength
(
I3
)
+
X
PerBlock
-
1
)
/
X
PerBlock
;
constexpr
unsigned
XBlockWork
=
(
out_desc
.
GetLength
(
I3
)
+
Wo
PerBlock
-
1
)
/
Wo
PerBlock
;
const
unsigned
block_id
=
constexpr
auto
in_block_glb_desc
=
make_ConstantTensorDescriptor
(
blockIdx
.
x
+
blockIdx
.
y
*
gridDim
.
x
+
blockIdx
.
z
*
(
gridDim
.
y
*
gridDim
.
x
);
Sequence
<
NPerBlock
,
CPerBlockLoop
,
HiPerBlock
,
WiPerBlock
>
{},
in_desc
.
GetStrides
());
constexpr
auto
wei_block_glb_desc
=
make_ConstantTensorDescriptor
(
Sequence
<
KPerBlock
,
CPerBlockLoop
,
S
,
R
>
{},
wei_desc
.
GetStrides
());
constexpr
auto
in_block_desc
=
constexpr
auto
out_block_glb_desc
=
make_ConstantTensorDescriptor
(
make_ConstantTensorDescriptor
(
Sequence
<
NPerBlock
,
Sequence
<
NPerBlock
,
KPerBlock
,
HoPerBlock
,
WoPerBlock
>
{},
out_desc
.
GetStrides
());
CPerBlockLoop
,
YPerBlock
*
OutTileSizeH
+
S
-
1
,
XPerBlock
*
OutTileSizeW
+
R
-
1
>
{});
constexpr
auto
wei_block_desc
=
constexpr
auto
in_block_lds_desc
=
make_ConstantTensorDescriptor
(
Sequence
<
KPerBlock
,
CPerBlockLoop
,
S
,
R
>
{});
make_ConstantTensorDescriptor
(
in_block_glb_desc
.
GetLengths
());
constexpr
auto
wei_block_lds_desc
=
make_ConstantTensorDescriptor
(
wei_block_glb_desc
.
GetLengths
());
constexpr
auto
out_block_lds_desc
=
make_ConstantTensorDescriptor
(
out_block_glb_desc
.
GetLengths
());
constexpr
auto
out_block_desc
=
make_ConstantTensorDescriptor
(
constexpr
unsigned
in_block_size
=
in_block_lds_desc
.
GetElementSize
();
Sequence
<
NPerBlock
,
KPerBlock
,
YPerBlock
*
OutTileSizeH
,
XPerBlock
*
OutTileSizeW
>
{});
constexpr
unsigned
wei_block_size
=
wei_block_lds_desc
.
GetElementSize
();
constexpr
unsigned
out_block_size
=
out_block_lds_desc
.
GetElementSize
();
__shared__
TFloat
p_in_block
[
NPerBlock
*
CPerBlockLoop
*
(
YPerBlock
*
OutTileSizeH
+
S
-
1
)
*
__shared__
TFloat
p_in_block
[
in_block_size
];
(
XPerBlock
*
OutTileSizeW
+
R
-
1
)];
__shared__
TFloat
p_wei_block
[
wei_block_size
];
__shared__
TFloat
p_wei_block
[
KPerBlock
*
CPerBlockLoop
*
S
*
R
];
__shared__
TFloat
p_out_block
[
out_block_size
];
__shared__
TFloat
p_out_block
[
NPerBlock
*
KPerBlock
*
(
YPerBlock
*
OutTileSizeH
)
*
(
XPerBlock
*
OutTileSizeW
)];
const
unsigned
block_id
=
blockIdx
.
x
+
blockIdx
.
y
*
gridDim
.
x
+
blockIdx
.
z
*
(
gridDim
.
y
*
gridDim
.
x
);
unsigned
itmp
=
block_id
;
unsigned
itmp
=
block_id
;
unsigned
n_block_work_id
=
itmp
/
(
KBlockWork
*
YBlockWork
*
XBlockWork
);
unsigned
n_block_work_id
=
itmp
/
(
KBlockWork
*
YBlockWork
*
XBlockWork
);
...
@@ -471,6 +474,34 @@ __global__ void gridwise_convolution(InDesc,
...
@@ -471,6 +474,34 @@ __global__ void gridwise_convolution(InDesc,
unsigned
hi_block_work_begin
=
ho_block_work_begin
;
// minus padding
unsigned
hi_block_work_begin
=
ho_block_work_begin
;
// minus padding
unsigned
wi_block_work_begin
=
wo_block_work_begin
;
// minus padding
unsigned
wi_block_work_begin
=
wo_block_work_begin
;
// minus padding
#if 0
if(threadIdx.x == 0)
{
print_ConstantTensorDescriptor( in_desc, "gridwise_convolution: in_desc: ");
print_ConstantTensorDescriptor(wei_desc, "gridwise_convolution: wei_desc: ");
print_ConstantTensorDescriptor(out_desc, "gridwise_convolution: out_desc: ");
print_ConstantTensorDescriptor( in_block_glb_desc, "gridwise_convolution: in_block_glb_desc: ");
print_ConstantTensorDescriptor(wei_block_glb_desc, "gridwise_convolution: wei_block_glb_desc: ");
print_ConstantTensorDescriptor(out_block_glb_desc, "gridwise_convolution: out_block_glb_desc: ");
print_ConstantTensorDescriptor( in_block_lds_desc, "gridwise_convolution: in_block_lds_desc: ");
print_ConstantTensorDescriptor(wei_block_lds_desc, "gridwise_convolution: wei_block_lds_desc: ");
print_ConstantTensorDescriptor(out_block_lds_desc, "gridwise_convolution: out_block_lds_desc: ");
printf("NBlockWork %u, KBlockWork %u, YBlockWork %u, XBlockWork %u \t"
"block_id %u, n_block_work_id %u, k_block_work_id %u, y_block_work_id %u, "
"x_block_work_id %u\n",
NBlockWork,
KBlockWork,
YBlockWork,
XBlockWork,
block_id,
n_block_work_id,
k_block_work_id,
y_block_work_id,
x_block_work_id);
}
#endif
for
(
unsigned
c_block_work_begin
=
0
;
c_block_work_begin
<
in_desc
.
GetLength
(
I1
);
for
(
unsigned
c_block_work_begin
=
0
;
c_block_work_begin
<
in_desc
.
GetLength
(
I1
);
c_block_work_begin
+=
CPerBlockLoop
)
c_block_work_begin
+=
CPerBlockLoop
)
{
{
...
@@ -478,81 +509,94 @@ __global__ void gridwise_convolution(InDesc,
...
@@ -478,81 +509,94 @@ __global__ void gridwise_convolution(InDesc,
// copy input tensor to LDS
// copy input tensor to LDS
blockwise_4d_tensor_op
<
TFloat
,
blockwise_4d_tensor_op
<
TFloat
,
decltype
(
in_desc
),
decltype
(
in_
block_glb_
desc
),
decltype
(
in_block_desc
),
decltype
(
in_block_
lds_
desc
),
NBlockCopyLen0
,
NBlockCopyLen0
,
NBlockCopyLen1
,
NBlockCopyLen1
,
NBlockCopyLen2
,
NBlockCopyLen2
,
NBlockCopyLen3
,
NBlockCopyLen3
,
decltype
(
f_copy
)
>
(
in_desc
,
decltype
(
f_copy
)
>
(
p_in
+
in_desc
.
Get1dIndex
(
n_block_work_begin
,
in_block_glb_desc
,
c_block_work_begin
,
p_in
+
in_block_glb_desc
.
Get1dIndex
(
n_block_work_begin
,
hi_block_work_begin
,
c_block_work_begin
,
wi_block_work_begin
),
hi_block_work_begin
,
in_block_desc
,
wi_block_work_begin
),
p_in_block
,
in_block_lds_desc
,
f_copy
);
p_in_block
,
f_copy
);
#if 1
// copy weight tensor to LDS
// copy weight tensor to LDS
blockwise_4d_tensor_op
<
TFloat
,
blockwise_4d_tensor_op
<
TFloat
,
decltype
(
wei_desc
),
decltype
(
wei_
block_glb_
desc
),
decltype
(
wei_block_desc
),
decltype
(
wei_block_
lds_
desc
),
NBlockCopyLen0
,
NBlockCopyLen0
,
NBlockCopyLen1
,
NBlockCopyLen1
,
NBlockCopyLen2
,
NBlockCopyLen2
,
NBlockCopyLen3
,
NBlockCopyLen3
,
decltype
(
f_copy
)
>
(
decltype
(
f_copy
)
>
(
wei_desc
,
wei_
block_glb_
desc
,
p_wei
+
wei_desc
.
Get1dIndex
(
k_block_work_begin
,
c_block_work_begin
,
0
,
0
),
p_wei
+
wei_
block_glb_
desc
.
Get1dIndex
(
k_block_work_begin
,
c_block_work_begin
,
0
,
0
),
wei_block_desc
,
wei_block_
lds_
desc
,
p_wei_block
,
p_wei_block
,
f_copy
);
f_copy
);
// copy output tensor to LDS
// copy output tensor to LDS
blockwise_4d_tensor_op
<
TFloat
,
blockwise_4d_tensor_op
<
TFloat
,
decltype
(
out_desc
),
decltype
(
out_
block_glb_
desc
),
decltype
(
out_block_desc
),
decltype
(
out_block_
lds_
desc
),
NBlockCopyLen0
,
NBlockCopyLen0
,
NBlockCopyLen1
,
NBlockCopyLen1
,
NBlockCopyLen2
,
NBlockCopyLen2
,
NBlockCopyLen3
,
NBlockCopyLen3
,
decltype
(
f_copy
)
>
(
out_desc
,
decltype
(
f_copy
)
>
(
p_out
+
out_desc
.
Get1dIndex
(
n_block_work_begin
,
out_block_glb_desc
,
k_block_work_begin
,
p_out
+
out_block_glb_desc
.
Get1dIndex
(
n_block_work_begin
,
ho_block_work_begin
,
k_block_work_begin
,
wo_block_work_begin
),
ho_block_work_begin
,
out_block_desc
,
wo_block_work_begin
),
p_out_block
,
out_block_lds_desc
,
f_copy
);
p_out_block
,
f_copy
);
#if 0
__syncthreads();
__syncthreads();
#endif
// blockwise convolution
// blockwise convolution
blockwise_convolution
<
TFloat
,
blockwise_convolution
<
TFloat
,
decltype
(
in_block_desc
),
decltype
(
in_block_
lds_
desc
),
decltype
(
wei_block_desc
),
decltype
(
wei_block_
lds_
desc
),
decltype
(
out_block_desc
),
decltype
(
out_block_
lds_
desc
),
OutTileSizeH
,
OutTileSizeH
,
OutTileSizeW
>
(
OutTileSizeW
>
(
in_block_lds_desc
,
in_block_desc
,
p_in_block
,
wei_block_desc
,
p_wei_block
,
out_block_desc
,
p_out_block
);
p_in_block
,
wei_block_lds_desc
,
p_wei_block
,
out_block_lds_desc
,
p_out_block
);
#if 0
__syncthreads();
__syncthreads();
#endif
// accum output tensor from LDS to device mem
// accum output tensor from LDS to device mem
blockwise_4d_tensor_op
<
TFloat
,
blockwise_4d_tensor_op
<
TFloat
,
decltype
(
out_block_desc
),
decltype
(
out_block_
lds_
desc
),
decltype
(
out_desc
),
decltype
(
out_
block_glb_
desc
),
NBlockCopyLen0
,
NBlockCopyLen0
,
NBlockCopyLen1
,
NBlockCopyLen1
,
NBlockCopyLen2
,
NBlockCopyLen2
,
NBlockCopyLen3
,
NBlockCopyLen3
,
decltype
(
f_copy
)
>
(
out_block_desc
,
decltype
(
f_copy
)
>
(
p_out_block
,
out_block_lds_desc
,
out_desc
,
p_out_block
,
p_out
+
out_desc
.
Get1dIndex
(
n_block_work_begin
,
out_block_glb_desc
,
k_block_work_begin
,
p_out
+
out_block_glb_desc
.
Get1dIndex
(
n_block_work_begin
,
ho_block_work_begin
,
k_block_work_begin
,
wo_block_work_begin
),
ho_block_work_begin
,
f_copy
);
wo_block_work_begin
),
f_copy
);
#endif
}
}
}
}
src/include/constant_tensor_descriptor.cuh
View file @
84b36bc1
...
@@ -24,20 +24,6 @@ struct Sequence
...
@@ -24,20 +24,6 @@ struct Sequence
}
}
};
};
#if 0
template<class F, class T, T... Is>
void for_each(F f, std::integer_sequence<T, Is...>)
{
f(Is)...;
}
template<class F, class T, T N>
void for_n_time(F f, Constant<T, N>)
{
for_each(f, std::make_integer_sequence<T, N>{});
}
#endif
template
<
class
Lengths
,
class
Strides
>
template
<
class
Lengths
,
class
Strides
>
struct
ConstantTensorDescriptor
struct
ConstantTensorDescriptor
{
{
...
@@ -67,17 +53,33 @@ struct ConstantTensorDescriptor
...
@@ -67,17 +53,33 @@ struct ConstantTensorDescriptor
return
Strides
{}.
Get
(
Index
<
I
>
{});
return
Strides
{}.
Get
(
Index
<
I
>
{});
}
}
#if 0
// this is ugly, only for 4d
template <class... Is>
__host__
__device__
constexpr
unsigned
GetElementSize
()
const
__host__ __device__ unsigned Get1dIndex(Is... is) const
{
static_assert
(
nDim
==
4
,
"nDim is not 4"
);
constexpr
auto
I0
=
Index
<
0
>
{};
constexpr
auto
I1
=
Index
<
1
>
{};
constexpr
auto
I2
=
Index
<
2
>
{};
constexpr
auto
I3
=
Index
<
3
>
{};
return
GetLength
(
I0
)
*
GetLength
(
I1
)
*
GetLength
(
I2
)
*
GetLength
(
I3
);
}
// this is ugly, only for 4d
__host__
__device__
constexpr
unsigned
GetElementSpace
()
const
{
{
static_assert(nDim == sizeof...(Is), "nDim not consistent");
static_assert
(
nDim
==
4
,
"nDim is not 4"
);
const unsigned iss[nDim] = {static_cast<unsigned>(is)...};
unsigned idx = 0;
constexpr
auto
I0
=
Index
<
0
>
{};
for_n_time([&](auto iDim) { idx += iss[iDim] * GetStride<iDim>(); }, NDimConstant{});
constexpr
auto
I1
=
Index
<
1
>
{};
return idx;
constexpr
auto
I2
=
Index
<
2
>
{};
constexpr
auto
I3
=
Index
<
3
>
{};
return
(
GetLength
(
I0
)
-
1
)
*
GetStride
(
I0
)
+
(
GetLength
(
I1
)
-
1
)
*
GetStride
(
I1
)
+
(
GetLength
(
I2
)
-
1
)
*
GetStride
(
I2
)
+
(
GetLength
(
I3
)
-
1
)
*
GetStride
(
I3
)
+
1
;
}
}
#elif
1
// this is ugly, only for 4d
// this is ugly, only for 4d
__host__
__device__
unsigned
Get1dIndex
(
unsigned
n
,
unsigned
c
,
unsigned
h
,
unsigned
w
)
const
__host__
__device__
unsigned
Get1dIndex
(
unsigned
n
,
unsigned
c
,
unsigned
h
,
unsigned
w
)
const
{
{
...
@@ -86,10 +88,9 @@ struct ConstantTensorDescriptor
...
@@ -86,10 +88,9 @@ struct ConstantTensorDescriptor
constexpr
auto
I2
=
Index
<
2
>
{};
constexpr
auto
I2
=
Index
<
2
>
{};
constexpr
auto
I3
=
Index
<
3
>
{};
constexpr
auto
I3
=
Index
<
3
>
{};
static_assert
(
nDim
==
4
,
"nDim
not consistent
"
);
static_assert
(
nDim
==
4
,
"nDim
is not 4
"
);
return
n
*
GetStride
(
I0
)
+
c
*
GetStride
(
I1
)
+
h
*
GetStride
(
I2
)
+
w
*
GetStride
(
I3
);
return
n
*
GetStride
(
I0
)
+
c
*
GetStride
(
I1
)
+
h
*
GetStride
(
I2
)
+
w
*
GetStride
(
I3
);
}
}
#endif
};
};
// this is ugly, only for 4d
// this is ugly, only for 4d
...
@@ -145,7 +146,7 @@ __host__ __device__ constexpr auto get_output_4d_tensor_descriptor(InDesc, WeiDe
...
@@ -145,7 +146,7 @@ __host__ __device__ constexpr auto get_output_4d_tensor_descriptor(InDesc, WeiDe
// this is ugly, only for 4d
// this is ugly, only for 4d
template
<
class
TDesc
>
template
<
class
TDesc
>
__host__
__device__
void
print_ConstantTensorDescriptor
(
TDesc
)
__host__
__device__
void
print_ConstantTensorDescriptor
(
TDesc
,
const
char
*
s
)
{
{
constexpr
auto
desc
=
TDesc
{};
constexpr
auto
desc
=
TDesc
{};
...
@@ -156,7 +157,8 @@ __host__ __device__ void print_ConstantTensorDescriptor(TDesc)
...
@@ -156,7 +157,8 @@ __host__ __device__ void print_ConstantTensorDescriptor(TDesc)
static_assert
(
desc
.
GetDimension
()
==
4
,
"dim is not 4"
);
static_assert
(
desc
.
GetDimension
()
==
4
,
"dim is not 4"
);
printf
(
"dim %u, lengths {%u %u %u %u}, strides {%u %u %u %u}
\n
"
,
printf
(
"%s dim %u, lengths {%u %u %u %u}, strides {%u %u %u %u}
\n
"
,
s
,
desc
.
GetDimension
(),
desc
.
GetDimension
(),
desc
.
GetLength
(
I0
),
desc
.
GetLength
(
I0
),
desc
.
GetLength
(
I1
),
desc
.
GetLength
(
I1
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment