From 13e4280f827935b5efc6e543f26f307c6881ac41 Mon Sep 17 00:00:00 2001 From: Zhou Wei <52485244+zhouwei25@users.noreply.github.com> Date: Wed, 3 Mar 2021 11:42:02 +0800 Subject: [PATCH] [Custom OP]polish doc of custom OP (#31369) --- .../fluid/extension/include/ext_exception.h | 2 +- paddle/fluid/framework/data_feed.cc | 14 ++-- .../framework/details/exception_holder.h | 2 +- .../fluid/tests/custom_op/test_check_error.cc | 2 +- .../utils/cpp_extension/cpp_extension.py | 64 +++++++++++-------- 5 files changed, 46 insertions(+), 38 deletions(-) diff --git a/paddle/fluid/extension/include/ext_exception.h b/paddle/fluid/extension/include/ext_exception.h index f6ea7570c86..632d91d5285 100644 --- a/paddle/fluid/extension/include/ext_exception.h +++ b/paddle/fluid/extension/include/ext_exception.h @@ -102,7 +102,7 @@ class ErrorMessage { do { \ auto __message__ = ::paddle::ErrorMessage(__VA_ARGS__).to_string(); \ throw ::paddle::PD_Exception(__message__, __FILE__, __LINE__, \ - "An error occured."); \ + "An error occurred."); \ } while (0) } // namespace paddle diff --git a/paddle/fluid/framework/data_feed.cc b/paddle/fluid/framework/data_feed.cc index 1ab0b401350..6f244ee1713 100644 --- a/paddle/fluid/framework/data_feed.cc +++ b/paddle/fluid/framework/data_feed.cc @@ -519,7 +519,7 @@ bool MultiSlotDataFeed::CheckFile(const char* filename) { VLOG(0) << "error: the number of ids is a negative number: " << num; VLOG(0) << "please check line<" << instance_cout << "> in file<" << filename << ">"; - VLOG(0) << "Error occured when parsing " << i + VLOG(0) << "Error occurred when parsing " << i << " th slot with total slots number: " << all_slots_.size(); return false; } else if (num == 0) { @@ -530,14 +530,14 @@ bool MultiSlotDataFeed::CheckFile(const char* filename) { "characters."; VLOG(0) << "please check line<" << instance_cout << "> in file<" << filename << ">"; - VLOG(0) << "Error occured when parsing " << i + VLOG(0) << "Error occurred when parsing " << i << " th slot with total slots number: " << all_slots_.size(); return false; } else if (errno == ERANGE || num > INT_MAX) { VLOG(0) << "error: the number of ids greater than INT_MAX"; VLOG(0) << "please check line<" << instance_cout << "> in file<" << filename << ">"; - VLOG(0) << "Error occured when parsing " << i + VLOG(0) << "Error occurred when parsing " << i << " th slot with total slots number: " << all_slots_.size(); return false; } @@ -549,7 +549,7 @@ bool MultiSlotDataFeed::CheckFile(const char* filename) { "representable values for float"; VLOG(0) << "please check line<" << instance_cout << "> in file<" << filename << ">"; - VLOG(0) << "Error occured when parsing " << i + VLOG(0) << "Error occurred when parsing " << i << " th slot with total slots number: " << all_slots_.size(); VLOG(0) << "and in this slot: " << j @@ -558,7 +558,7 @@ bool MultiSlotDataFeed::CheckFile(const char* filename) { } if (j + 1 != num && endptr - str == len) { VLOG(0) << "error: there is a wrong with the number of ids."; - VLOG(0) << "Error occured when parsing " << i + VLOG(0) << "Error occurred when parsing " << i << " th slot with total slots number: " << all_slots_.size(); VLOG(0) << "and in this slot: " << j @@ -574,7 +574,7 @@ bool MultiSlotDataFeed::CheckFile(const char* filename) { if (errno == ERANGE) { VLOG(0) << "error: the value is out of the range of " "representable values for uint64_t"; - VLOG(0) << "Error occured when parsing " << i + VLOG(0) << "Error occurred when parsing " << i << " th slot with total slots number: " << all_slots_.size(); VLOG(0) << "and in this slot: " << j @@ -585,7 +585,7 @@ bool MultiSlotDataFeed::CheckFile(const char* filename) { } if (j + 1 != num && endptr - str == len) { VLOG(0) << "error: there is a wrong with the number of ids."; - VLOG(0) << "Error occured when parsing " << i + VLOG(0) << "Error occurred when parsing " << i << " th slot with total slots number: " << all_slots_.size(); VLOG(0) << "and in this slot: " << j diff --git a/paddle/fluid/framework/details/exception_holder.h b/paddle/fluid/framework/details/exception_holder.h index 66c490724c5..1fb802b3f65 100644 --- a/paddle/fluid/framework/details/exception_holder.h +++ b/paddle/fluid/framework/details/exception_holder.h @@ -108,7 +108,7 @@ class ExceptionHolder { type_ = kNone; } - // NOTE: currently in PE, multiple exceptions may occured in multiple + // NOTE: currently in PE, multiple exceptions may occurred in multiple // threads, and the exception that occur later will overwrite that // occur earlier, but what we want should be the first triggered exception. // However, EOF exception is lower priority exception and can be overwritten, diff --git a/python/paddle/fluid/tests/custom_op/test_check_error.cc b/python/paddle/fluid/tests/custom_op/test_check_error.cc index 305b05daa63..eda521a8966 100644 --- a/python/paddle/fluid/tests/custom_op/test_check_error.cc +++ b/python/paddle/fluid/tests/custom_op/test_check_error.cc @@ -21,7 +21,7 @@ TEST(PD_THROW, empty) { } catch (const std::exception& e) { caught_exception = true; std::string err_msg = e.what(); - EXPECT_TRUE(err_msg.find("An error occured.") != std::string::npos); + EXPECT_TRUE(err_msg.find("An error occurred.") != std::string::npos); #if _WIN32 EXPECT_TRUE(err_msg.find("tests\\custom_op\\test_check_error.cc:20") != std::string::npos); diff --git a/python/paddle/utils/cpp_extension/cpp_extension.py b/python/paddle/utils/cpp_extension/cpp_extension.py index 5d132217bba..6c730f64895 100644 --- a/python/paddle/utils/cpp_extension/cpp_extension.py +++ b/python/paddle/utils/cpp_extension/cpp_extension.py @@ -52,24 +52,28 @@ def setup(**attr): It encapsulates the python built-in ``setuptools.setup`` function and keeps arguments and usage same as the native interface. Meanwhile, it hiddens Paddle inner framework concepts, such as necessary compiling flags, included paths of head files, and linking - flags. It also will automatically search and valid local enviromment and versions of ``cc`` and - ``nvcc`` , then compiles customized operators supporting CPU or GPU device according to - the specified Extension type. + flags. It also will automatically search and valid local enviromment and versions of + ``cc(Linux)`` , ``cl.exe(Windows)`` and ``nvcc`` , then compiles customized operators + supporting CPU or GPU device according to the specified Extension type. Moreover, `ABI compatibility `_ - will be checked to ensure that compiler version from ``cc`` + will be checked to ensure that compiler version from ``cc(Linux)`` , ``cl.exe(Windows)`` on local machine is compatible with pre-installed Paddle whl in python site-packages. - For example if Paddle with CUDA 10.1 is built with GCC 8.2, then the version of user's - local machine should satisfy GCC >= 8.2. Otherwise, a fatal error will occur because of - ABI compatibility. - .. note:: + For Linux, GCC version will be checked . For example if Paddle with CUDA 10.1 is built with GCC 8.2, + then the version of user's local machine should satisfy GCC >= 8.2. + For Windows, Visual Studio version will be checked, and it shoule be greater than or equal to that of + PaddlePaddle (Visual Studio 2015 update3). + If the above conditions are not met, the corresponding warning will be printed, and a fatal error may + occur because of ABI compatibility. - 1. Compiler ABI compatibility is forward compatible. On Linux platform, - we recommend to use GCC 8.2 as soft linking condidate of ``/usr/bin/cc`` . - 2. Using ``which cc`` to ensure location of ``cc`` and using ``cc --version`` - to ensure linking GCC version on Linux. - 3. Currently we support Linux and Windows platfrom. MacOS is supporting... + .. note:: + + 1. Currently we support Linux and Windows platfrom. MacOS is supporting... + 2. On Linux platform, we recommend to use GCC 8.2 as soft linking condidate of ``/usr/bin/cc`` . + Then, Use ``which cc`` to ensure location of ``cc`` and using ``cc --version`` to ensure linking + GCC version. + 3. On Windows platform, we recommend to install `` Visual Studio`` (>=2015 update3). Compared with Just-In-Time ``load`` interface, it only compiles once by executing @@ -673,19 +677,23 @@ def load(name, append user defined custom operators in background while building models. It will perform compiling, linking, Python API generation and module loading - processes under a individual subprocess. It does not require CMake or Ninja environment - and only ``g++/nvcc`` on Linux and clang++ on MacOS. For example it requires - GCC compiler with version is greater than 5.4 and linked into ``/usr/bin/cc`` . - If compiling Operators supporting GPU device, please make sure ``nvcc`` compiler - is installed in local environment. - + processes under a individual subprocess. It does not require CMake or Ninja + environment. On Linux platform, it requires GCC compiler whose version is + greater than 5.4 and it should be soft linked to ``/usr/bin/cc`` . On Windows + platform, it requires Visual Studio whose version is greater than 2015 update3. + On MacOS, clang++ is requited. In addition, if compiling Operators supporting + GPU device, please make sure ``nvcc`` compiler is installed in local environment. Moreover, `ABI compatibility `_ - will be checked to ensure that compiler version from ``cc`` + will be checked to ensure that compiler version from ``cc(Linux)`` , ``cl.exe(Windows)`` on local machine is compatible with pre-installed Paddle whl in python site-packages. - For example if Paddle with CUDA 10.1 is built with GCC 8.2, then the version of user's - local machine should satisfy GCC >= 8.2. Otherwise, a fatal error will occur because of - ABI compatibility. + + For Linux, GCC version will be checked . For example if Paddle with CUDA 10.1 is built with GCC 8.2, + then the version of user's local machine should satisfy GCC >= 8.2. + For Windows, Visual Studio version will be checked, and it shoule be greater than or equal to that of + PaddlePaddle (Visual Studio 2015 update3). + If the above conditions are not met, the corresponding warning will be printed, and a fatal error may + occur because of ABI compatibility. Compared with ``setup`` interface, it doesn't need extra ``setup.py`` and excute ``python setup.py install`` command. The interface contains all compiling and installing @@ -693,11 +701,11 @@ def load(name, .. note:: - 1. Compiler ABI compatibility is forward compatible. On Linux platform, - we recommend to use GCC 8.2 as soft linking condidate of ``/usr/bin/cc`` . - 2. Using ``which cc`` to ensure location of ``cc`` and using ``cc --version`` - to ensure linking GCC version on Linux. - 3. Currenly we support Linux and Windows platfrom. MacOS is supporting... + 1. Currently we support Linux and Windows platfrom. MacOS is supporting... + 2. On Linux platform, we recommend to use GCC 8.2 as soft linking condidate of ``/usr/bin/cc`` . + Then, Use ``which cc`` to ensure location of ``cc`` and using ``cc --version`` to ensure linking + GCC version. + 3. On Windows platform, we recommend to install `` Visual Studio`` (>=2015 update3). **A simple example:** -- GitLab