From 7a7c8fd9e5a1fce083acb9458aa242dc762f45b0 Mon Sep 17 00:00:00 2001 From: tensor-tang Date: Fri, 13 Oct 2017 22:05:34 +0800 Subject: [PATCH] simplify some comments and code --- paddle/gserver/layers/MKLDNNConvLayer.cpp | 2 +- paddle/gserver/layers/MKLDNNLayer.h | 9 ++++---- paddle/trainer/tests/CMakeLists.txt | 28 ++++++++++------------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/paddle/gserver/layers/MKLDNNConvLayer.cpp b/paddle/gserver/layers/MKLDNNConvLayer.cpp index 92a1334af..8b67a1ef4 100644 --- a/paddle/gserver/layers/MKLDNNConvLayer.cpp +++ b/paddle/gserver/layers/MKLDNNConvLayer.cpp @@ -315,7 +315,7 @@ void MKLDNNConvLayer::resetOutValue( } else { cpuOutVal_ = out; } - // when output is cpu device, change the mkldnn output value and make they + // when output is cpu device, change the mkldnn output value and make them // share the same data. Then if next layer use inputlayer->getOuputValue() // to achieve the input value, it will get the right data. output_.value = std::dynamic_pointer_cast(cpuOutVal_); diff --git a/paddle/gserver/layers/MKLDNNLayer.h b/paddle/gserver/layers/MKLDNNLayer.h index 31867477c..5f9923da7 100644 --- a/paddle/gserver/layers/MKLDNNLayer.h +++ b/paddle/gserver/layers/MKLDNNLayer.h @@ -268,9 +268,9 @@ protected: /** * reset the output grad matrix from primitive desc. * and reset the merge grad primitive if needed. - * note: when this layer have serval output, - * do not support mixing with cpu device, - * because can not get memory desc from cpu device. + * note: when this layer has serval outputs, + * it could not be mixed with cpu device, + * since it can not get memory desc from cpu device. */ virtual void resetOutGrad(MKLDNNMatrixPtr& out, mkldnn::memory::primitive_desc pd) { @@ -281,7 +281,7 @@ protected: if (outputMap_.size() <= 1) { return; } - std::vector scales; + std::vector scales(outputMap_.size(), 1.0); std::vector srcPDs; std::vector srcs; for (auto it = outputMap_.begin(); it != outputMap_.end(); ++it) { @@ -297,7 +297,6 @@ protected: } srcPDs.push_back(src->getPrimitiveDesc()); srcs.push_back(*src); - scales.push_back(1.0); } // TODO(TJ): remove me when mkldnn sum support different formats diff --git a/paddle/trainer/tests/CMakeLists.txt b/paddle/trainer/tests/CMakeLists.txt index db87ea205..5ebbb99c9 100644 --- a/paddle/trainer/tests/CMakeLists.txt +++ b/paddle/trainer/tests/CMakeLists.txt @@ -39,22 +39,18 @@ add_test(NAME test_CompareTwoNets ################ test_CompareMKLDNNandCPU ###################### if(WITH_MKLDNN) - add_unittest_without_exec(test_CompareMKLDNNandCPU - test_CompareTwoNets.cpp) - add_test(NAME test_CompareMKLDNNandCPU - COMMAND ${PADDLE_SOURCE_DIR}/paddle/.set_python_path.sh -d ${PADDLE_SOURCE_DIR}/python/ - ${CMAKE_CURRENT_BINARY_DIR}/test_CompareMKLDNNandCPU - --config_file_a=trainer/tests/sample_trainer_config_simple_net.conf --use_mkldnn_a=True - --config_file_b=trainer/tests/sample_trainer_config_simple_net.conf --use_mkldnn_b=False - --use_gpu=False - WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}/paddle/) - add_test(NAME test_CompareMKLDNNandCPU_Banches - COMMAND ${PADDLE_SOURCE_DIR}/paddle/.set_python_path.sh -d ${PADDLE_SOURCE_DIR}/python/ - ${CMAKE_CURRENT_BINARY_DIR}/test_CompareMKLDNNandCPU - --config_file_a=trainer/tests/sample_trainer_config_branch_net.conf --use_mkldnn_a=True - --config_file_b=trainer/tests/sample_trainer_config_branch_net.conf --use_mkldnn_b=False - --use_gpu=False - WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}/paddle/) + macro(gen_command VAR_NAME CONFIG_FILE) + set(${VAR_NAME} "${PADDLE_SOURCE_DIR}/paddle/.set_python_path.sh" "-d" "${PADDLE_SOURCE_DIR}/python/" + "${CMAKE_CURRENT_BINARY_DIR}/test_CompareMKLDNNandCPU --use_gpu=False" + "--config_file_a=trainer/tests/${CONFIG_FILE} --use_mkldnn_a=True" + "--config_file_b=trainer/tests/${CONFIG_FILE} --use_mkldnn_b=False" + "WORKING_DIRECTORY" "${PADDLE_SOURCE_DIR}/paddle/") + endmacro() + add_unittest_without_exec(test_CompareMKLDNNandCPU test_CompareTwoNets.cpp) + gen_command(compare_simple_net "sample_trainer_config_simple_net.conf") + gen_command(compare_branch_net "sample_trainer_config_branch_net.conf") + add_test(NAME test_CompareMKLDNNandCPU_simple_net COMMAND ${compare_simple_net}) + add_test(NAME test_CompareMKLDNNandCPU_branch_net COMMAND ${compare_branch_net}) endif() ############### test_CompareTwoOpts ################### -- GitLab