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

Auto compare cpu and gpu function. #643

Merged
merged 11 commits into from
Dec 5, 2016

Conversation

hedaoyuan
Copy link
Contributor

@hedaoyuan hedaoyuan commented Nov 28, 2016

Making it easier to write unittest for comparing gpu and cpu version of a function.
For a detailed description, see issue #385
这个PR部分解决issue #385的问题(详细描述见issue),对test_matrixCompare.cpp里面的test case进行了重构,一部分放到了test_Matrix.cpp里面,一部分放到了test_BaseMatrix.cpp里面,其他的test case另外再起issue和pr解决。

该PR新增一个autotest::AutoCompare,使用AutoCompare对一个成员函数进行CPU/GPU实现的对比,主要步骤如下:

  1. 构造一个AutoCompare对象,AutoCompare对象里面会包含一个CpuMatrix和一个GpuMatrix对象;
  2. 初始化成员函数所需的参数(只需要初始化CPU部分的参数)
  3. 通过cmpWithArg模板函数对成员函数进行CPU和GPU实现的测试。
AutoCompare test(...);
Init Argument arg1,arg2...
test.cmpWithArg(function, arg1, arg2....)

Copy link
Collaborator

@wangkuiyi wangkuiyi left a comment

Choose a reason for hiding this comment

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

这个PR新增的代码是删掉的代码行数的三倍。它带来了这么好处呢?应该在PR的description里说明。

#include <gtest/gtest.h>
#include "paddle/math/Matrix.h"

using namespace paddle; // NOLINT
Copy link
Collaborator

@wangkuiyi wangkuiyi Nov 28, 2016

Choose a reason for hiding this comment

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

如果一定要用using namespace,应该写在 namespace autotest {里面吧?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

Copy link
Collaborator

Choose a reason for hiding this comment

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

这个 header file 里没有 include guard 也没有 pragma once吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

#include "paddle/math/Matrix.h"
#include "TensorCheck.h"

using namespace paddle; // NOLINT
Copy link
Collaborator

Choose a reason for hiding this comment

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

Google style guide 里建议不用 using namespace是有原因的 https://google.github.io/styleguide/cppguide.html#Namespaces 。这里可以

using paddle::BaseMatrix;
using paddle::CpuMatrix;
using paddle::GpuMatrix;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.
用using可以清楚的知道这个文件里面Test了哪些东西。

@hedaoyuan
Copy link
Contributor Author

这个PR还没写完。另外,test_BaseMatrix.cpp里面的那些test相当于都是新增的,原来并没有覆盖到这些测试。

@hedaoyuan
Copy link
Contributor Author

AutoCompare当前支持Matrix函数的比较,后续会通过别的PR增加对Vector、SparseMatrix等类型的比较。

@hedaoyuan hedaoyuan merged commit 17f7125 into PaddlePaddle:develop Dec 5, 2016

inline int operator()(real a, real b) {
if (std::fabs(a - b) > err_) {
if ((std::fabs(a - b) / std::fabs(a)) > (err_ / 10.0f)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we check a != 0 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

还是需要的,另外提一个issue来fix这个把。

zhhsplendid pushed a commit to zhhsplendid/Paddle that referenced this pull request Sep 25, 2019
* update_install_doc

* follow_comments
zhhsplendid pushed a commit to zhhsplendid/Paddle that referenced this pull request Sep 25, 2019
* synchronize with develop (PaddlePaddle#642)

* update_commitid1.3 (PaddlePaddle#641)

* update inference c++ API doc (PaddlePaddle#634)

* update inference c++ API doc

* fix link

* thorough clean for doc (PaddlePaddle#644)

* thorough clean

* delete_DS_Store

* Cherrypick1.3 (PaddlePaddle#652)

* thorough clean

* delete_DS_Store

* [Don't merge now]update_install_doc (PaddlePaddle#643)

* update_install_doc

* follow_comments

* add maxdepth (PaddlePaddle#646)

* upload_md (PaddlePaddle#649)

* update_version (PaddlePaddle#650)

* Translation of 16 new apis (PaddlePaddle#651)

* fix_windows

* Final update 1.3 (PaddlePaddle#653)

* thorough clean

* delete_DS_Store

* update_1.3

* Deadlink fix (PaddlePaddle#654)

* fix_deadlinks

* update_docker

* Update release_note.rst

* Update index_cn.rst

* update_Paddle (PaddlePaddle#658)

* fix pic (PaddlePaddle#659)

* [to 1.3] cn api debug (PaddlePaddle#655) (PaddlePaddle#661)

* debug

* fix 2 -conv2d

* "锚" ==> anchor(s)
zhhsplendid pushed a commit to zhhsplendid/Paddle that referenced this pull request Sep 25, 2019
* synchronize with develop (PaddlePaddle#642)

* update_commitid1.3 (PaddlePaddle#641)

* update inference c++ API doc (PaddlePaddle#634)

* update inference c++ API doc

* fix link

* thorough clean for doc (PaddlePaddle#644)

* thorough clean

* delete_DS_Store

* Cherrypick1.3 (PaddlePaddle#652)

* thorough clean

* delete_DS_Store

* [Don't merge now]update_install_doc (PaddlePaddle#643)

* update_install_doc

* follow_comments

* add maxdepth (PaddlePaddle#646)

* upload_md (PaddlePaddle#649)

* update_version (PaddlePaddle#650)

* Translation of 16 new apis (PaddlePaddle#651)

* fix_windows

* Final update 1.3 (PaddlePaddle#653)

* thorough clean

* delete_DS_Store

* update_1.3

* Deadlink fix (PaddlePaddle#654)

* fix_deadlinks

* update_docker

* Update release_note.rst

* Update index_cn.rst

* update_Paddle (PaddlePaddle#658)

* fix pic (PaddlePaddle#659)

* [to 1.3] cn api debug (PaddlePaddle#655) (PaddlePaddle#661)

* debug

* fix 2 -conv2d

* "锚" ==> anchor(s)

* Weekly cherrypick0302 (PaddlePaddle#668)

* Update programming_guide.md (PaddlePaddle#664)

* Update programming_guide.md

* Update programming_guide_en.md

* Update cn api to 1.3 (PaddlePaddle#663)

* Update cn api to 1.3 fluid & layers

* Rest to 1.3

* Weeklyupdate 0301 (PaddlePaddle#666)

* Tables_rm_op

* update_op

* update_index

* update_book_0302 (PaddlePaddle#667)

* fix_format (PaddlePaddle#669) (PaddlePaddle#670)

* fix_format

* Update Tables.md

* Update Tables_en.md

* add dataset api_cn (PaddlePaddle#673)

* rm fluid.core in desigin_idea (PaddlePaddle#674)

* Update fluid_design_idea.md

* Update fluid_design_idea_en.md

* Fix array_read code example error. (PaddlePaddle#671)

Signed-off-by: zhaoyuchen <zhaoyuchen01@baidu.com>

* add data_reader_cn (PaddlePaddle#676)

* fix doc error (PaddlePaddle#675)

* update_book_commitid (PaddlePaddle#680)

* update_book_commitid

* commitid0309

* fix typo

* book indexes (PaddlePaddle#677)
heavengate pushed a commit to heavengate/Paddle that referenced this pull request Aug 24, 2022
* Add QAT in GPT example

* Add QAT in GPT example
AnnaTrainingG pushed a commit to AnnaTrainingG/Paddle that referenced this pull request Sep 19, 2022
* add styleclip

* update 2022

* add weight url

* update doc & img url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants