An Interface to automatically compile C++/CUDA source files Just-In-Time and return callable python function as other Paddle layers API. It will append user defined custom operators in background while building models. It will perform compiling, linking, Python API generation and m
(
name: str,
sources: Sequence[str],
extra_cxx_cflags: Sequence[str] | None = None,
extra_cuda_cflags: Sequence[str] | None = None,
extra_ldflags: Sequence[str] | None = None,
extra_include_paths: Sequence[str] | None = None,
extra_library_paths: Sequence[str] | None = None,
build_directory: str | None = None,
verbose: bool = False,
)
| 1331 | |
| 1332 | |
| 1333 | def load( |
| 1334 | name: str, |
| 1335 | sources: Sequence[str], |
| 1336 | extra_cxx_cflags: Sequence[str] | None = None, |
| 1337 | extra_cuda_cflags: Sequence[str] | None = None, |
| 1338 | extra_ldflags: Sequence[str] | None = None, |
| 1339 | extra_include_paths: Sequence[str] | None = None, |
| 1340 | extra_library_paths: Sequence[str] | None = None, |
| 1341 | build_directory: str | None = None, |
| 1342 | verbose: bool = False, |
| 1343 | ) -> ModuleType: |
| 1344 | """ |
| 1345 | An Interface to automatically compile C++/CUDA source files Just-In-Time |
| 1346 | and return callable python function as other Paddle layers API. It will |
| 1347 | append user defined custom operators in background while building models. |
| 1348 | |
| 1349 | It will perform compiling, linking, Python API generation and module loading |
| 1350 | processes under a individual subprocess. It does not require CMake or Ninja |
| 1351 | environment. On Linux platform, it requires GCC compiler whose version is |
| 1352 | greater than 5.4 and it should be soft linked to ``/usr/bin/cc`` . On Windows |
| 1353 | platform, it requires Visual Studio whose version is greater than 2017. |
| 1354 | On MacOS, clang++ is requited. In addition, if compiling Operators supporting |
| 1355 | GPU device, please make sure ``nvcc`` compiler is installed in local environment. |
| 1356 | |
| 1357 | Moreover, `ABI compatibility <https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html>`_ |
| 1358 | will be checked to ensure that compiler version from ``cc(Linux)`` , ``cl.exe(Windows)`` |
| 1359 | on local machine is compatible with pre-installed Paddle whl in python site-packages. |
| 1360 | |
| 1361 | For Linux, GCC version will be checked . For example if Paddle with CUDA 10.1 is built with GCC 8.2, |
| 1362 | then the version of user's local machine should satisfy GCC >= 8.2. |
| 1363 | For Windows, Visual Studio version will be checked, and it should be greater than or equal to that of |
| 1364 | PaddlePaddle (Visual Studio 2017). |
| 1365 | If the above conditions are not met, the corresponding warning will be printed, and a fatal error may |
| 1366 | occur because of ABI compatibility. |
| 1367 | |
| 1368 | Compared with ``setup`` interface, it doesn't need extra ``setup.py`` and execute |
| 1369 | ``python setup.py install`` command. The interface contains all compiling and installing |
| 1370 | process underground. |
| 1371 | |
| 1372 | Note: |
| 1373 | |
| 1374 | 1. Currently we support Linux, MacOS and Windows platform. |
| 1375 | 2. On Linux platform, we recommend to use GCC 8.2 as soft linking candidate of ``/usr/bin/cc`` . |
| 1376 | Then, Use ``which cc`` to ensure location of ``cc`` and using ``cc --version`` to ensure linking |
| 1377 | GCC version. |
| 1378 | 3. On Windows platform, we recommend to install `` Visual Studio`` (>=2017). |
| 1379 | |
| 1380 | |
| 1381 | **A simple example:** |
| 1382 | |
| 1383 | .. code-block:: text |
| 1384 | |
| 1385 | import paddle |
| 1386 | from paddle.utils.cpp_extension import load |
| 1387 | |
| 1388 | custom_op_module = load( |
| 1389 | name="op_shared_library_name", # name of shared library |
| 1390 | sources=['relu_op.cc', 'relu_op.cu'], # source files of customized op |