Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobilenet gpu implementation #2776

Merged
merged 37 commits into from
Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
211f83f
set depthwise conv layer interface in python
NHZlX Jul 4, 2017
eeb17c2
add depthwise operation and depthwise conv layer
NHZlX Jul 4, 2017
efae51c
add the mobilenet gpu acceleration, cpu is in the process
NHZlX Jul 7, 2017
f4e7ae5
add mobilenet gpu grad test, the test is ok
NHZlX Jul 7, 2017
36e7800
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 7, 2017
064dc88
add the comments for .h file and code tiny modify
NHZlX Jul 10, 2017
198164a
use the expandconvlayer forward and backward, add the explain for class
NHZlX Jul 10, 2017
a3ce6aa
add depthwise conv test
NHZlX Jul 10, 2017
e92f002
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 10, 2017
fd4b113
move DepthwiseConvOpTest.cpp to ConvOpTest.cpp
NHZlX Jul 12, 2017
433935a
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 12, 2017
2bc08f8
modify format accored with clang-format 3.8
NHZlX Jul 12, 2017
ccd46d1
modify format accored with clang-format 3.8
NHZlX Jul 12, 2017
030a3db
the groups default should be None
NHZlX Jul 12, 2017
fc8aedb
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 12, 2017
c43f693
modify the format and delete useless comment
NHZlX Jul 14, 2017
6267312
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 14, 2017
02e04b4
fuse the conv and depthwise conv together
NHZlX Jul 18, 2017
11588b3
support inputchannels != outputchannels of depthwiseconv
NHZlX Jul 18, 2017
d43fbba
add comments for python api
NHZlX Jul 18, 2017
44927bf
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 18, 2017
dbb6588
modity the format
NHZlX Jul 18, 2017
66520af
accelerate inputbackward(delete 'if' in this func) of depthwise conv
NHZlX Jul 19, 2017
d50c71f
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 19, 2017
f7390d1
delete useless .h header in DepthwiseConvOpGpu.cu
NHZlX Jul 19, 2017
21ab0eb
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 19, 2017
77ff97a
fuse interface of depthwise to expand in python api
NHZlX Jul 19, 2017
8199886
fuse interface of depthwise to expandconv
NHZlX Jul 19, 2017
1f516fa
modify format, and modify the layer grad test, op test
NHZlX Jul 19, 2017
bd54eb9
tiny modify the test
NHZlX Jul 19, 2017
4d6be97
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 20, 2017
5b07d4e
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 20, 2017
248149f
add depthwiseconv test and fix the little bug of the convOpTest
NHZlX Jul 20, 2017
d5b0c57
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 20, 2017
cfd4c05
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 21, 2017
e8d171b
add check for groups and inputChannels
NHZlX Jul 21, 2017
6c528cb
add check: CHECK_EQ(outputs[0].getArgType(), ADD_TO)
NHZlX Jul 21, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 115 additions & 19 deletions paddle/function/ConvOpTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,22 @@ class ConvolutionTest {
ConvolutionTest(const std::string& conv1,
const std::string& conv2,
TestType type,
bool useGroups = true,
std::string algo = "auto") {
for (size_t batchSize : {1, 32}) {
for (size_t inputSize : {7, 14, 54}) {
for (size_t filterSize : {1, 3, 5}) {
for (size_t inputChannels : {3, 64}) {
for (size_t outputChannels : {3, 64, 128}) {
if (inputChannels < outputChannels) break;
for (size_t outputChannels : {3, 64}) {
if (inputChannels > outputChannels) break;
size_t groups;
if (!useGroups) {
groups = 1;
} else {
if (outputChannels % inputChannels != 0) continue;
groups = inputChannels;
}

for (size_t stride : {1, 2}) {
for (size_t padding : {0, 1}) {
if (padding >= filterSize) break;
Expand All @@ -62,13 +71,24 @@ class ConvolutionTest {
FuncConfig()
.set("paddings", paddings)
.set("strides", strides)
.set("groups", (size_t)1)
.set("groups", groups)
.set("algo", algo));

TensorShape input{
batchSize, inputChannels, inputSize, inputSize};
TensorShape filter{
outputChannels, inputChannels, filterSize, filterSize};

TensorShape filter;
if (groups > 1)
filter = TensorShape({groups,
outputChannels / groups,
inputChannels / groups,
filterSize,
filterSize});
else
filter = TensorShape({outputChannels,
inputChannels,
filterSize,
filterSize});
TensorShape output{
batchSize, outputChannels, outputSize, outputSize};

Expand All @@ -85,7 +105,8 @@ class ConvolutionTest {
} else if (type == kBackwardFilterTest) {
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, output));
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, input));
test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, filter));
test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, filter),
ADD_TO);
test.run();
}
}
Expand All @@ -106,14 +127,23 @@ class ConvolutionTest2 {
ConvolutionTest2(const std::string& conv1,
const std::string& conv2,
TestType type,
bool useGroups = true,
std::string algo = "auto") {
for (size_t batchSize : {16}) {
for (size_t inputHeight : {7, 31}) {
for (size_t inputWidth : {10, 54}) {
for (size_t filterHeight : {1, 5}) {
for (size_t filterWidth : {3, 7}) {
for (size_t inputChannels : {7}) {
for (size_t outputChannels : {32}) {
for (size_t outputChannels : {7}) {
size_t groups;
if (!useGroups) {
groups = 1;
} else {
if (outputChannels % inputChannels != 0) continue;
groups = inputChannels;
}

size_t stride = 1;
size_t padding = 0;
size_t outputHeight =
Expand Down Expand Up @@ -141,13 +171,24 @@ class ConvolutionTest2 {
FuncConfig()
.set("paddings", paddings)
.set("strides", strides)
.set("groups", (size_t)1)
.set("groups", groups)
.set("algo", algo));

TensorShape input{
batchSize, inputChannels, inputHeight, inputWidth};
TensorShape filter{
outputChannels, inputChannels, filterHeight, filterWidth};

TensorShape filter;
if (groups > 1)
filter = TensorShape({groups,
outputChannels / groups,
inputChannels / groups,
filterHeight,
filterWidth});
else
filter = TensorShape({outputChannels,
inputChannels,
filterHeight,
filterWidth});
TensorShape output{
batchSize, outputChannels, outputHeight, outputWidth};

Expand All @@ -164,7 +205,8 @@ class ConvolutionTest2 {
} else if (type == kBackwardFilterTest) {
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, output));
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, input));
test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, filter));
test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, filter),
ADD_TO);
test.run();
}
}
Expand All @@ -177,34 +219,88 @@ class ConvolutionTest2 {
}
};

// ======Start Convolution TEST======

TEST(Forward, GEMM) {
ConvolutionTest<DEVICE_TYPE_CPU, DEVICE_TYPE_CPU> test(
"NaiveConv-CPU", "GemmConv-CPU", kForwardTest);
"NaiveConv-CPU", "GemmConv-CPU", kForwardTest, false);
ConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_CPU> test2(
"NaiveConv-CPU", "GemmConv-CPU", kForwardTest);
"NaiveConv-CPU", "GemmConv-CPU", kForwardTest, false);
}

#ifndef PADDLE_ONLY_CPU
TEST(Forward, GEMM2) {
ConvolutionTest<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test(
"GemmConv-CPU", "GemmConv-GPU", kForwardTest);
"GemmConv-CPU", "GemmConv-GPU", kForwardTest, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以在接口参数上直接defualt=false,这里少写个参数。

Copy link
Contributor Author

@NHZlX NHZlX Jul 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认的是true, 所以depthwise conv 不用传参数

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也可以,不过depthwise是优化特例,所以defualt=false更好。

ConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test2(
"GemmConv-CPU", "GemmConv-GPU", kForwardTest);
"GemmConv-CPU", "GemmConv-GPU", kForwardTest, false);
}

TEST(BackwardInput, GEMM) {
ConvolutionTest<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test(
"GemmConvGradInput-CPU", "GemmConvGradInput-GPU", kBackwardInputTest);
"GemmConvGradInput-CPU",
"GemmConvGradInput-GPU",
kBackwardInputTest,
false);
ConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test2(
"GemmConvGradInput-CPU", "GemmConvGradInput-GPU", kBackwardInputTest);
"GemmConvGradInput-CPU",
"GemmConvGradInput-GPU",
kBackwardInputTest,
false);
}

TEST(BackwardFilter, GEMM) {
ConvolutionTest<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test(
"GemmConvGradFilter-CPU", "GemmConvGradFilter-GPU", kBackwardFilterTest);
"GemmConvGradFilter-CPU",
"GemmConvGradFilter-GPU",
kBackwardFilterTest,
false);
ConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test2(
"GemmConvGradFilter-CPU", "GemmConvGradFilter-GPU", kBackwardFilterTest);
"GemmConvGradFilter-CPU",
"GemmConvGradFilter-GPU",
kBackwardFilterTest,
false);
}
#endif
// ======End Convolution TEST======

// ======Start DepthwiseConvolution TEST======

// TODO(zhaolong) The depthwise convolution cpu test will be added when the cpu
// version of depthwiseConv is implemented.

#ifndef PADDLE_ONLY_CPU

TEST(DepthwiseConvForward, GEMM2) {
ConvolutionTest<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test(
"GemmConv-CPU", "DepthwiseConv-GPU", kForwardTest);
ConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test2(
"GemmConv-CPU", "DepthwiseConv-GPU", kForwardTest);
}

TEST(DepthwiseConvBackwardInput, GEMM) {
ConvolutionTest<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test(
"GemmConvGradInput-CPU",
"DepthwiseConvGradInput-GPU",
kBackwardInputTest);
ConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test2(
"GemmConvGradInput-CPU",
"DepthwiseConvGradInput-GPU",
kBackwardInputTest);
}

TEST(DepthwiseConvBackwardFilter, GEMM) {
ConvolutionTest<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test(
"GemmConvGradFilter-CPU",
"DepthwiseConvGradFilter-GPU",
kBackwardFilterTest);
ConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test2(
"GemmConvGradFilter-CPU",
"DepthwiseConvGradFilter-GPU",
kBackwardFilterTest);
}

#endif
// ======End DepthwiseConvolution TEST======

} // namespace paddle
Loading