-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Mobilenet gpu implementation #2776
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
Merged
Merged
Changes from 15 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 eeb17c2
add depthwise operation and depthwise conv layer
NHZlX efae51c
add the mobilenet gpu acceleration, cpu is in the process
NHZlX f4e7ae5
add mobilenet gpu grad test, the test is ok
NHZlX 36e7800
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX 064dc88
add the comments for .h file and code tiny modify
NHZlX 198164a
use the expandconvlayer forward and backward, add the explain for class
NHZlX a3ce6aa
add depthwise conv test
NHZlX e92f002
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX fd4b113
move DepthwiseConvOpTest.cpp to ConvOpTest.cpp
NHZlX 433935a
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX 2bc08f8
modify format accored with clang-format 3.8
NHZlX ccd46d1
modify format accored with clang-format 3.8
NHZlX 030a3db
the groups default should be None
NHZlX fc8aedb
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX c43f693
modify the format and delete useless comment
NHZlX 6267312
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX 02e04b4
fuse the conv and depthwise conv together
NHZlX 11588b3
support inputchannels != outputchannels of depthwiseconv
NHZlX d43fbba
add comments for python api
NHZlX 44927bf
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX dbb6588
modity the format
NHZlX 66520af
accelerate inputbackward(delete 'if' in this func) of depthwise conv
NHZlX d50c71f
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX f7390d1
delete useless .h header in DepthwiseConvOpGpu.cu
NHZlX 21ab0eb
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX 77ff97a
fuse interface of depthwise to expand in python api
NHZlX 8199886
fuse interface of depthwise to expandconv
NHZlX 1f516fa
modify format, and modify the layer grad test, op test
NHZlX bd54eb9
tiny modify the test
NHZlX 4d6be97
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX 5b07d4e
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX 248149f
add depthwiseconv test and fix the little bug of the convOpTest
NHZlX d5b0c57
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX cfd4c05
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX e8d171b
add check for groups and inputChannels
NHZlX 6c528cb
add check: CHECK_EQ(outputs[0].getArgType(), ADD_TO)
NHZlX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,6 +177,156 @@ class ConvolutionTest2 { | |
| } | ||
| }; | ||
|
|
||
| template <DeviceType DType1, DeviceType DType2> | ||
| class DepthwiseConvolutionTest { | ||
| public: | ||
| DepthwiseConvolutionTest(const std::string& conv1, | ||
| const std::string& conv2, | ||
| TestType type, | ||
| 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 : {64, 128}) { | ||
| size_t outputChannels = inputChannels; | ||
|
||
| for (size_t stride : {1, 2}) { | ||
| for (size_t padding : {0, 1}) { | ||
| if (padding >= filterSize) break; | ||
| size_t outputSize = | ||
| (inputSize - filterSize + 2 * padding + stride) / stride; | ||
| VLOG(3) << " batchSize=" << batchSize | ||
| << " inputChannels=" << inputChannels | ||
| << " inputHeight=" << inputSize | ||
| << " inputWidth=" << inputSize | ||
| << " outputChannels=" << outputChannels | ||
| << " filterHeight=" << filterSize | ||
| << " filterWidth=" << filterSize | ||
| << " outputHeight=" << outputSize | ||
| << " outputWidth=" << outputSize << " stride=" << stride | ||
| << " padding=" << padding; | ||
|
|
||
| std::vector<size_t> paddings = {padding, padding}; | ||
| std::vector<size_t> strides = {stride, stride}; | ||
| size_t groups = inputChannels; | ||
| Compare2Function<DType1, DType2> test( | ||
| conv1, | ||
| conv2, | ||
| FuncConfig() | ||
| .set("paddings", paddings) | ||
| .set("strides", strides) | ||
| .set("groups", groups) | ||
| .set("algo", algo)); | ||
|
|
||
| TensorShape input{ | ||
| batchSize, inputChannels, inputSize, inputSize}; | ||
| TensorShape filter{inputChannels, 1, 1, filterSize, filterSize}; | ||
| TensorShape output{ | ||
| batchSize, outputChannels, outputSize, outputSize}; | ||
|
|
||
| if (type == kForwardTest) { | ||
| test.addInputs(BufferArg(VALUE_TYPE_FLOAT, input)); | ||
| test.addInputs(BufferArg(VALUE_TYPE_FLOAT, filter)); | ||
| test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, output)); | ||
| test.run(); | ||
| } else if (type == kBackwardInputTest) { | ||
| test.addInputs(BufferArg(VALUE_TYPE_FLOAT, output)); | ||
| test.addInputs(BufferArg(VALUE_TYPE_FLOAT, filter)); | ||
| test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, input), ADD_TO); | ||
| test.run(); | ||
| } 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.run(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // Mainly used to test cases where the height and width (input, filter) | ||
| // are not equal. | ||
| template <DeviceType DType1, DeviceType DType2> | ||
| class DepthwiseConvolutionTest2 { | ||
| public: | ||
| DepthwiseConvolutionTest2(const std::string& conv1, | ||
| const std::string& conv2, | ||
| TestType type, | ||
| 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 : {32}) { | ||
| size_t outputChannels = inputChannels; | ||
| size_t stride = 1; | ||
| size_t padding = 0; | ||
| size_t outputHeight = | ||
| (inputHeight - filterHeight + 2 * padding + stride) / | ||
| stride; | ||
| size_t outputWidth = | ||
| (inputWidth - filterWidth + 2 * padding + stride) / stride; | ||
| VLOG(3) << " batchSize=" << batchSize | ||
| << " inputChannels=" << inputChannels | ||
| << " inputHeight=" << inputHeight | ||
| << " inputWidth=" << inputWidth | ||
| << " outputChannels=" << outputChannels | ||
| << " filterHeight=" << filterHeight | ||
| << " filterWidth=" << filterWidth | ||
| << " outputHeight=" << outputHeight | ||
| << " outputWidth=" << outputWidth | ||
| << " stride=" << stride << " padding=" << padding; | ||
|
|
||
| std::vector<size_t> paddings = {padding, padding}; | ||
| std::vector<size_t> strides = {stride, stride}; | ||
| size_t groups = inputChannels; | ||
| Compare2Function<DType1, DType2> test( | ||
| conv1, | ||
| conv2, | ||
| FuncConfig() | ||
| .set("paddings", paddings) | ||
| .set("strides", strides) | ||
| .set("groups", groups) | ||
| .set("algo", algo)); | ||
|
|
||
| TensorShape input{ | ||
| batchSize, inputChannels, inputHeight, inputWidth}; | ||
| TensorShape filter{ | ||
| inputChannels, 1, 1, filterHeight, filterWidth}; | ||
| TensorShape output{ | ||
| batchSize, outputChannels, outputHeight, outputWidth}; | ||
|
|
||
| if (type == kForwardTest) { | ||
| test.addInputs(BufferArg(VALUE_TYPE_FLOAT, input)); | ||
| test.addInputs(BufferArg(VALUE_TYPE_FLOAT, filter)); | ||
| test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, output)); | ||
| test.run(); | ||
| } else if (type == kBackwardInputTest) { | ||
| test.addInputs(BufferArg(VALUE_TYPE_FLOAT, output)); | ||
| test.addInputs(BufferArg(VALUE_TYPE_FLOAT, filter)); | ||
| test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, input), ADD_TO); | ||
| test.run(); | ||
| } 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.run(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // ======Start Convolution TEST====== | ||
| TEST(Forward, GEMM) { | ||
| ConvolutionTest<DEVICE_TYPE_CPU, DEVICE_TYPE_CPU> test( | ||
| "NaiveConv-CPU", "GemmConv-CPU", kForwardTest); | ||
|
|
@@ -206,5 +356,49 @@ TEST(BackwardFilter, GEMM) { | |
| "GemmConvGradFilter-CPU", "GemmConvGradFilter-GPU", kBackwardFilterTest); | ||
| } | ||
| #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, GEMM) { | ||
|
||
| DepthwiseConvolutionTest<DEVICE_TYPE_GPU, DEVICE_TYPE_GPU> test( | ||
| "GemmConv-GPU", "DepthwiseConv-GPU", kForwardTest); | ||
| DepthwiseConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test2( | ||
| "GemmConv-GPU", "DepthwiseConv-GPU", kForwardTest); | ||
| } | ||
|
|
||
| TEST(DepthwiseConvForward, GEMM2) { | ||
| DepthwiseConvolutionTest<DEVICE_TYPE_GPU, DEVICE_TYPE_GPU> test( | ||
| "DepthwiseConv-GPU", "DepthwiseConv-GPU", kForwardTest); | ||
| DepthwiseConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test2( | ||
| "DepthwiseConv-GPU", "DepthwiseConv-GPU", kForwardTest); | ||
| } | ||
|
|
||
| TEST(DepthwiseConvBackwardInput, GEMM) { | ||
| DepthwiseConvolutionTest<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test( | ||
| "DepthwiseConvGradInput-GPU", | ||
| "DepthwiseConvGradInput-GPU", | ||
| kBackwardInputTest); | ||
| DepthwiseConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test2( | ||
| "DepthwiseConvGradInput-GPU", | ||
| "DepthwiseConvGradInput-GPU", | ||
| kBackwardInputTest); | ||
| } | ||
|
|
||
| TEST(DepthwiseConvBackwardFilter, GEMM) { | ||
| DepthwiseConvolutionTest<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test( | ||
| "DepthwiseConvGradFilter-GPU", | ||
| "DepthwiseConvGradFilter-GPU", | ||
| kBackwardFilterTest); | ||
| DepthwiseConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test2( | ||
| "DepthwiseConvGradFilter-GPU", | ||
| "DepthwiseConvGradFilter-GPU", | ||
| kBackwardFilterTest); | ||
| } | ||
| #endif | ||
| // ======End DepthwiseConvolution TEST====== | ||
|
|
||
| } // namespace paddle | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我主要的意思是,看一下
DepthwiseConvolutionTest是否可以用ConvolutionTest替换,这两个大部分代码都是一样的。