Intel® Oneapi Programming Guide
Total Page:16
File Type:pdf, Size:1020Kb
Intel® oneAPI Programming Guide Intel Corporation www.intel.com Notices and Disclaimers Contents Notices and Disclaimers....................................................................... 5 Chapter 1: Introduction oneAPI Programming Model Overview ..........................................................7 Data Parallel C++ (DPC++)................................................................8 oneAPI Toolkit Distribution..................................................................9 About This Guide.......................................................................................9 Related Documentation ..............................................................................9 Chapter 2: oneAPI Programming Model Sample Program ..................................................................................... 10 Platform Model........................................................................................ 14 Execution Model ...................................................................................... 15 Memory Model ........................................................................................ 17 Memory Objects.............................................................................. 19 Accessors....................................................................................... 19 Synchronization .............................................................................. 20 Unified Shared Memory.................................................................... 20 Kernel Programming Model ....................................................................... 21 C++ Language Requirements ........................................................... 21 DPC++ Synchronization ................................................................... 23 Error Handling ................................................................................ 25 Fall Back ........................................................................................ 26 Chapter 3: Programming Interface Single Source Compilation ........................................................................ 27 Compiler Drivers ..................................................................................... 27 Example Compilation ............................................................................... 27 API-Based Code .............................................................................. 27 Direct Programming ........................................................................ 29 Compilation Model ................................................................................... 29 Compile to Object Step .................................................................... 31 Link to Executable Step.................................................................... 32 Execute Step .................................................................................. 33 Online Compilation ......................................................................... 33 CPU Flow................................................................................................ 33 Example CPU Commands ................................................................. 33 Online Compilation for CPU............................................................... 34 Offline Compilation for CPU............................................................... 34 Optimization Flags for CPU Architectures ............................................ 34 Host and Kernel Interaction on CPU ................................................... 35 GPU Flow ............................................................................................... 35 Example GPU Commands ................................................................. 35 Offline Compilation for GPU .............................................................. 35 FPGA Flow .............................................................................................. 35 Example FPGA Commands................................................................ 38 Offline Compilation for FPGA............................................................. 38 Targeting Multiple FPGAs.................................................................. 42 Other Supported Intel oneAPI DPC++ Compiler Options for FPGA .......... 42 2 Contents FPGA Device Selection in the Host Code ............................................. 43 Host and Kernel Interaction on FPGA.................................................. 43 FPGA Workflows in IDEs ................................................................... 44 Complex Scenario: Use of Static Libraries ................................................... 45 Create the Static Library .................................................................. 45 Use the Static Library ...................................................................... 45 Standard Intel oneAPI DPC++ Compiler Options.......................................... 45 Chapter 4: Data Parallel C++ (DPC++) Programming Language and Runtime C++ Version Support ............................................................................... 47 Header Files and Namespaces ................................................................... 47 DPC++ Classes, Class Templates, and Defines............................................. 47 Accessor ........................................................................................ 49 Atomic........................................................................................... 50 Buffer............................................................................................ 50 Command Group Handler ................................................................. 51 Context ......................................................................................... 51 Device ........................................................................................... 51 Device Event .................................................................................. 52 Device Selector............................................................................... 52 Event ............................................................................................ 53 Exception....................................................................................... 53 Group............................................................................................ 54 ID ................................................................................................. 54 Image ........................................................................................... 54 Item.............................................................................................. 55 Kernel ........................................................................................... 55 Multi-pointer................................................................................... 55 Nd_item......................................................................................... 56 Nd_range....................................................................................... 56 Platform......................................................................................... 56 Program......................................................................................... 57 Queue ........................................................................................... 57 Range............................................................................................ 57 Stream .......................................................................................... 58 Vec and Swizzled Vec....................................................................... 58 Built-in Types & Functions ................................................................ 58 Property Interface ........................................................................... 59 Standard Library Classes Required for the Interface ............................. 59 Version .......................................................................................... 59 Memory Types......................................................................................... 59 Keywords ............................................................................................... 60 Preprocessor Directives and Macros ........................................................... 60 Chapter 5: API-based Programming oneAPI Library Overview .......................................................................... 61 Intel oneAPI DPC++ Library (oneDPL)........................................................ 61 oneDPL Library Usage ...................................................................... 61 oneDPL Code Samples ..................................................................... 62 Intel oneAPI Math Kernel Library (oneMKL) ................................................. 64 oneMKL Usage ................................................................................ 64 oneMKL Code Sample ...................................................................... 65 Intel oneAPI Threading Building Blocks (oneTBB) ......................................... 68 oneTBB Usage ................................................................................ 68 3 oneTBB Code Sample....................................................................... 68 Intel oneAPI Data Analytics Library (oneDAL) .............................................. 68 oneDAL Usage ...............................................................................