DOCA Documentation v2.0.2

DPACC Compiler

NVIDIA DOCA DPACC Compiler

This document describes DOCA DPACC Compiler and instructions about DPA toolchain setup and usage.

DPACC is a high-level compiler for the DPA processor. It compiles code targeted for the data-path accelerator (DPA) processor into an executable called as 'device executable' and generates a DPA program.

The DPA program is a host library with interfaces encapsulating the device executable. This DPA program is linked with the host application to generate a host executable. The host executable can invoke the DPA code through FlexIO runtime API.

DPACC uses DPA compiler (dpa-clang) to compile code targeted for DPA. dpa-clang is part of the DPA toolchain package which is an LLVM-based cross-compiling bare-metal toolchain. It provides Clang compiler, LLD linker targeting DPA architecture, and other utilities.

1.1. Glossary

Term Definition
Device DPA as present on the BlueField DPU
Host CPU that launches the device code to run on the DPA
Device function Any C function that runs on the DPA device
DPA global function Device function that is the point of entry when offloading any work on DPA
Host compiler Compiler used to compile the code targeting the host CPU
Device compiler Compiler used to compile code targeting the DPA
DPA program Host library that encapsulates the DPA device executable (.elf) and host stubs which are used to access the device executable

1.2. Offloading Work on DPA

offloading.png

To invoke a DPA function from host, the following things are required:

  • DPA device code – C programs, targeted to run on the DPA. DPA device code may contain one or more entry functions.
  • Host application code – the corresponding host application. Please refer to NVIDIA DOCA DPA Subsystem Programming Guide for more details
  • Runtime – FlexIO or DOCA DPA library provides the runtime

The generated DPA program, when linked with host application, results in a host executable containing both the host and device executables. The host application is in charge of loading the device executable on the device.

1.3. Writing DPA Applications

DPA device code is a C code with some restrictions and special definitions.

FlexIO or DOCA-DPA APIs provide interfaces to DPA.

1.3.1. Language Support

The DPA is programmed using a subset of the C11 language standard. The compiler documents any constructs that are not available. Language constructs, where available, retain their standard definitions.

1.3.2. Restrictions on DPA Code

  • Use of C thread local storage is not allowed for any variables
  • Identifiers with _dpacc prefix are reserved by the compiler. Use of such identifiers may result in an error or undefined behavior.
  • DPA processor does not have native floating-point support; use of floating point operations is disabled

1.3.3. DPA RPC Functions

A remote procedure call function is a synchronous call that triggers work in DPA and waits for its completion. It is annotated with a __dpa_rpc__ attribute.

For more information, please refer to NVIDIA DOCA DPA Subsystem Programming Guide.

1.3.4. DPA Global Functions

A DPA global function is a device function referenced from the host code. They are annotated with a __dpa_global__ attribute.

1.3.5. Characteristics of DPA Global Functions

  • Global functions cannot explicitly return a value. They must have void return type.
  • Global functions cannot accept C pointers and arrays as arguments (e.g., void my_global (int *ptr, int arr[]))
  • Global functions cannot accept a variable number of arguments
  • Inline specifier is not allowed on global functions

1.3.6. Handling User-defined Data Types

User-defined data types, when used as global function arguments, require special handling. They must be annotated with a __dpa_global__ attribute.

If the user-defined data type is typedef'd, the typedef statement must be annotated with a __dpa_global__ attribute along the data type itself.

1.3.7. Characteristics of Annotated Types

  • They must have a copy of the definition in all translation units where they are used as global function arguments
  • They cannot have pointers, variable length arrays, and flexible arrays as members
  • Fixed-size arrays as C structure members are supported
  • These characteristics apply recursively to any user-defined/typedef'd types that are members of an annotated type

DPACC processes all DPA global functions and annotated data structures and generates host and device interfaces to facilitate the function launch.

1.3.8. DPA Intrinsics

DPA features such as fences and processor-specific instructions are exposed via intrinsics by the DPA compiler. All intrinsics defined in the header file dpaintrin.h are guarded by the DPA_INTRIN_VERSION_USED macro. The current DPA_INTRIN_VERSION is 1.3. Example:

Copy
Copied!
            

#define DPA_INTRIN_VERSION_USED (DPA_INTRIN_VERSION(1, 3)) #include <dpaintrin.h> … __dpa_thread_writeback_window(); // Fence for write barrier


For more information, please refer to NVIDIA DOCA DPA Subsystem Programming Guide.

Package Instructions
Host compiler Compiler specified through hostcc option. Both gcc and clang are supported.
Note:

Minimum supported version for clang as hostcc is clang 3.8.0.

Device compiler The default device compiler is the "DPA compiler". Installing the DPACC package also installs the DPA compiler binaries dpa-clang, dpa-ar, dpa-nm and dpa-objdump.
Note:

dpa-clang is the only supported device compiler.

FlexIO SDK and C library Available as part of the DOCA software package. DPA toolchain does not provide C library and corresponding headers. Users are expected to use the C library for DPA from the FlexIO SDK.


2.1. Supported Versions


3.1. DPACC Inputs and Outputs

DPACC can produce DPA programs in a single command by accepting all source files as input. DPACC also offers the flexibility of producing DPA object files from individual source files.

DPA object files contain both host stub objects (DPACC-generated interfaces) and device objects. These DPA object files can later be given to DPACC as input to produce the DPA library.

Phase Option Name Default Output File Name
Compile input device code files to DPA object files --compile or -c .dpa.o appended to the name of each input source file
Compile and link the input device code files/DPA object files, and produce a DPA program No specific option No default name, output file name must be specified

DPACC can accept the following three file types as input:

File Extension File Type Description
.c C source file DPA device code
.dpa.o DPA object file Object file generated by DPACC, containing both host and device objects


Based on the mode of operations, DPACC can generate the two following output files:

Output File Type Input Files
DPA program C source files, DPA object files, and/or DPA object archives
DPA object file C source files

3.1.1. DPA Program

DPACC produces a DPA program in compile-and-link mode. A DPA program is a host library which contains:

  • DPACC-generated host stubs which facilitate invoking a DPA global function from the host application
  • Device executable, generated by DPACC by compiling input DPA device code

DPA program library has to be linked with the host application that contains appropriate runtime APIs to load the device executable onto DPA memory.

dpacc-output.png

3.1.2. DPA Object

DPACC produces DPA object files in compile-only mode. A DPA object is an object file for the host machine. In a DPA object, the device object generated by compiling the input device code file is placed inside a specific section of the generated host stubs object. This process is repeated for each input file.

3.2. DPACC Trajectory

The following diagram illustrates DPACC compile-and-link mode trajectory.

trajectory.png

3.3. Modes of Operation

This is a one-step mode that accepts C source files or DPA object files and produces the DPA program. Specifying the output library name is mandatory in this mode. Example commands:

Copy
Copied!
            

$ dpacc in1.c in2.c -o myLib1.a -hostcc=gcc # Takes C sources to produce myLib1.a library $ dpacc in3.dpa.o in4.dpa.o -o myLib2.a -hostcc=gcc # Takes DPA object files to produce myLib2.a library $ dpacc in1.c in3.dpa.o -o myLib3.a -hostcc=gcc # Takes C source and DPA object to produce myLib3.a library

3.3.2. Compile-only Mode

This mode accepts C source code and produces .dpa.o object files. These files can be given to DPACC to produce the DPA program. The mode is invoked by the --compile or -c option.

The user can explicitly provide the output object file name using the --output-file or -o option. Example commands:

Copy
Copied!
            

$ dpacc -c input1.c -hostcc=gcc # Produces input1.dpa.o $ dpacc -c input3.c input4.c -hostcc=gcc # Produces input3.dpa.o and input4.dpa.o $ dpacc -c input2.c -o myObj.dpa.o -hostcc=gcc # Produces myObj.dpa.o

To execute DOCA DPACC Compiler:

Copy
Copied!
            

Usage: dpacc <list-of-input-files> -hostcc=<path> [other options] Helper Flags: -h, --help                 Print help information about DPACC -V, --version               Print DPACC version information -v, --verbose               List the compilation commands generated by this invocation while also executing every command in verbose mode  -dryrun, --dryrun           Only list the compilation commands generated by DPACC, without executing them -keep, --keep Keep all intermediate files that are generated during internal compilation steps in the current directory -keep-dir, --keep-dir Keep all intermediate files that are generated during internal compilation steps in the given directory -optf, --options-file <file>,... Include command line options from the specified file

4.1. Mandatory Arguments

Flag DPACC Mode Description
List of one or more input files All List of C source files or DPA object file names. Specifying at least one input file is mandatory. A file with an unknown extension is treated as a DPA object file.
-hostcc, --hostcc <path> All Specify the host compiler. This is typically the native compiler present on the host system.
-o, --output-file <file> Compile-and-link Specify name and location of the output DPA program.

4.2. Commonly Used Arguments

Flag Description
-app-name, --app-name <name> Specify DPA application name for the DPA program. This option is required if multiple DPA programs are part of a host application because each DPA application must have a unique name. Default name is __dpa_a_out.
-devicecc-options, --devicecc-options <options>,... Specify the list of options to pass to the device compiler.
-devicelink-options, --devicelink-options <options>, ... Specify the list of options to pass during device linking stage. FlexIO libraries are linked by DPACC by default.
-I, --common-include-path <path>, ... Specify include search paths common to host and device code compilation. FlexIO headers paths are included by DPACC by default.
-devicecc, --devicecc <path> Specify the device compiler. By default, DPACC invokes dpa-clang.
-o, --output-file <file>

Specify name and location of the output file.

  • Compile-only mode – name of the output DPA object file. If not specified, .dpa.o is generated for each .c file.
  • Compiler-and-link mode – name of the output DPA program. This is a mandatory option in compiler-and-link mode.
-hostcc-options, --hostcc-options <options>, ... Specify the list of options to pass to the host compiler.
Important:

The devicecc-options option allows passing any option to the device compiler. However, passing options that prevent compilation of the input file may lead to unexpected behavior (e.g., -devicecc-options="-version" makes the device compiler print the version and not process input files).

Important:

Incompatible options that affect DPA global function argument sizes during DPACC invocation and host application compilation may lead to undefined behavior during execution (e.g., passing -hostcc-options="-fshort-enums" to DPACC and missing this option when building the host application).

4.3. Examples

This section provides some common use cases of DPACC and showcases the dpacc command.

This example specifies the names and paths of the libraries using devicelink-options:

Copy
Copied!
            

dpacc input.c -hostcc=gcc -o libInput.a -devicelink-options="-L <path-to-library> -l<libName>"

4.3.2. Include Headers

This example includes headers for device compilation using devicecc-options and host compilation using hostcc-options. You may also specify headers for any compilation on both the host and device side using the -I option.

Copy
Copied!
            

dpacc input.c -hostcc=gcc -o libInput.a -I <common-headers-path> -devicecc-options="-I <device-headers-path>" -hostcc-options="-I <host-headers-path>"

4.4. DPA Compiler Usage

dpa-clang is a compiler driver for accessing the Clang/LLVM compiler, assembler, and linker which accepts C code files or object files and generates an output according to different usage modes.

Note:

Invoking the compiler, assembler, or linker directly may lead to unexpected errors.


Refer to the following resources for detailed user guide and command line references:

4.4.1. Compiler Driver Command Line Options

Copy
Copied!
            

dpa-clang <list-of-input-files> [other-options]

4.4.2. Linker Command Line Options

LLD is the default linker provided in the DPA toolchain. Linker-related options are passed to through the compiler driver.

Copy
Copied!
            

dpa-clang -Wl,<linker-option>


For more information, please refer to the LLD command line reference.

4.4.3. dpacc-extract Command Line Options

dpacc-extract is a tool for extracting a device executable out of a DPA program or a host executable containing DPA program(s).

To execute dpacc-extract:

Copy
Copied!
            

Usage: dpacc-extract <input-file> -o=<output-file> [other options] Helper Flags: -o, --output-file Specify name of the output file -app-name, --app-name <name> Specify name of the DPA application to extract -h, --help                 Print help information about dpacc-extract -V, --version               Print dpacc-extract version information -optf, --options-file <file>,... Include command line options from the specified file


Mandatory arguments:

Flag Description
Input file DPA program or host executable containing DPA program. Specifying one input file is mandatory.
-o, --output-file <file> Specify name and location of the output device executable.
-app-name, --app-name <name> Specify name of the DPA application to extract. Mandatory if input file has multiple DPA apps.

4.4.4. Objdump Command Line Options

The dpa-objdump utility prints the contents of object files and final linked images named on the command line.

For more information, please refer to the Objdump command line reference. Commonly used dpa-objdump options:

Flag Description
--mcpu=nv-dpa-bf3 Option to choose micro-architecture for DPA processor. This option is not turned on by default.

4.4.5. Archiver Command Line Options

dpa-ar is a Unix ar-compatible archiver.

For more information, please refer to the Archiver command line reference.

4.4.6. NM Tool Command Line Options

The dpa-nm utility lists the names of symbols from object files and archives.

For more information, please refer to the NM tool command line reference.

4.4.7. Common Compiler Options

Flag Description
-mcpu=nv-dpa-bf3 Option to choose micro-architecture and ABI for DPA processor. This is the default option for the compiler.
-mrelax/-mno-relax Option to enable/disable linker relaxations.
-I <dir> Option to include header files present in <dir>.

4.4.8. Common Linker Options

Flag Description
-Wl,-L <path-to-library> -Wl,-l<library-name> Option to link against libraries

Note:

Linker options are provided through the compiler driver dpa-clang.

Note:

The LLD linker script is honored in addition to the default configuration rather than replacing the whole configuration like in GNU lD. Hence, additional options may be required to override some default behaviors.

4.4.9. Debugging Options

Flag Description
-fdebug-macro Option to emit macro debugging information. This option enables macro-debugging similar to GCC option -g3.

4.4.10. Miscellaneous Notes

  • DPA toolchain provides the ability to invoke GNU linker instead of the default LLD linker via the --fuse-ld=<arg> option in the command line reference. However, doing so is not recommended as it has not been tested.
  • Objects produced by LLD are not compatible with those generated by any other linker.

Notice

This document is provided for information purposes only and shall not be regarded as a warranty of a certain functionality, condition, or quality of a product. NVIDIA Corporation nor any of its direct or indirect subsidiaries and affiliates (collectively: “NVIDIA”) make no representations or warranties, expressed or implied, as to the accuracy or completeness of the information contained in this document and assume no responsibility for any errors contained herein. NVIDIA shall have no liability for the consequences or use of such information or for any infringement of patents or other rights of third parties that may result from its use. This document is not a commitment to develop, release, or deliver any Material (defined below), code, or functionality.

NVIDIA reserves the right to make corrections, modifications, enhancements, improvements, and any other changes to this document, at any time without notice.

Customer should obtain the latest relevant information before placing orders and should verify that such information is current and complete.

NVIDIA products are sold subject to the NVIDIA standard terms and conditions of sale supplied at the time of order acknowledgement, unless otherwise agreed in an individual sales agreement signed by authorized representatives of NVIDIA and customer (“Terms of Sale”). NVIDIA hereby expressly objects to applying any customer general terms and conditions with regards to the purchase of the NVIDIA product referenced in this document. No contractual obligations are formed either directly or indirectly by this document.

NVIDIA products are not designed, authorized, or warranted to be suitable for use in medical, military, aircraft, space, or life support equipment, nor in applications where failure or malfunction of the NVIDIA product can reasonably be expected to result in personal injury, death, or property or environmental damage. NVIDIA accepts no liability for inclusion and/or use of NVIDIA products in such equipment or applications and therefore such inclusion and/or use is at customer’s own risk.

NVIDIA makes no representation or warranty that products based on this document will be suitable for any specified use. Testing of all parameters of each product is not necessarily performed by NVIDIA. It is customer’s sole responsibility to evaluate and determine the applicability of any information contained in this document, ensure the product is suitable and fit for the application planned by customer, and perform the necessary testing for the application in order to avoid a default of the application or the product. Weaknesses in customer’s product designs may affect the quality and reliability of the NVIDIA product and may result in additional or different conditions and/or requirements beyond those contained in this document. NVIDIA accepts no liability related to any default, damage, costs, or problem which may be based on or attributable to: (i) the use of the NVIDIA product in any manner that is contrary to this document or (ii) customer product designs.

No license, either expressed or implied, is granted under any NVIDIA patent right, copyright, or other NVIDIA intellectual property right under this document. Information published by NVIDIA regarding third-party products or services does not constitute a license from NVIDIA to use such products or services or a warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property rights of the third party, or a license from NVIDIA under the patents or other intellectual property rights of NVIDIA.

Reproduction of information in this document is permissible only if approved in advance by NVIDIA in writing, reproduced without alteration and in full compliance with all applicable export laws and regulations, and accompanied by all associated conditions, limitations, and notices.

THIS DOCUMENT AND ALL NVIDIA DESIGN SPECIFICATIONS, REFERENCE BOARDS, FILES, DRAWINGS, DIAGNOSTICS, LISTS, AND OTHER DOCUMENTS (TOGETHER AND SEPARATELY, “MATERIALS”) ARE BEING PROVIDED “AS IS.” NVIDIA MAKES NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL NVIDIA BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT LIMITATION ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF ANY USE OF THIS DOCUMENT, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Notwithstanding any damages that customer might incur for any reason whatsoever, NVIDIA’s aggregate and cumulative liability towards customer for the products described herein shall be limited in accordance with the Terms of Sale for the product.

Trademarks

NVIDIA, the NVIDIA logo, and Mellanox are trademarks and/or registered trademarks of Mellanox Technologies Ltd. and/or NVIDIA Corporation in the U.S. and in other countries. The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world¬wide basis. Other company and product names may be trademarks of the respective companies with which they are associated.

Copyright

© 2023 NVIDIA Corporation & affiliates. All rights reserved.

© Copyright 2023, NVIDIA. Last updated on Nov 13, 2023.