|
lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
|
CUDA and GPU Async helpers (error checks, DataDev, CudaContext, FPGA and GPU memory mapping, DMA target selection, GPUTimer) from axi-pcie-devel. More...
#include "Utils.h"#include <string>#include "psdaq/aes-stream-drivers/GpuAsync.h"#include <assert.h>#include <stdint.h>#include <cuda.h>#include <cuda_runtime.h>Classes | |
| class | DataDev |
| Wraps a data_dev device so it can be automatically freed. More... | |
| class | CudaContext |
| Wraps a cuda context and handles some initialization for you. More... | |
| struct | GpuDmaBuffer_t |
| Describes FPGA memory that's mapped via RDMA to the GPU. More... | |
| struct | GpuBufferState_t |
| A read buffer and a write buffer on the GPU, mapped to the FPGA by gpuInitBufferState(). More... | |
| struct | GPUTimer |
| Class for timing various things. More... | |
Macros | |
| #define | deviceFunc |
| #define | globalFunc |
| Empty when not compiling with nvcc; global under nvcc. | |
| #define | hostFunc |
| Empty when not compiling with nvcc; host under nvcc. | |
| #define | NOARG "" |
| Empty string literal put in front of the optional message, so that the message argument is never empty (per the code comment). | |
| #define | chkFatal(rc, ...) checkError((rc), #rc, __FILE__, __LINE__, true, NOARG __VA_ARGS__) |
| Check a CUDA driver or runtime result rc with checkError(), logging any failure with the optional message and aborting. | |
| #define | chkError(rc, ...) checkError((rc), #rc, __FILE__, __LINE__, false, NOARG __VA_ARGS__) |
| Check a CUDA driver or runtime result rc with checkError(), logging any failure with the optional message without aborting; evaluates to true on failure. | |
Enumerations | |
| enum | DmaTgt_t { TGT_CPU =0x0 , TGT_GPU =0x1 , TGT_ERR =-1u } |
| Functions to get and set the DMA destination. More... | |
Functions | |
| bool | checkError (CUresult status, const char *func, const char *file, int line, bool crash=true, const char *msg="") |
| If status is not CUDA_SUCCESS, log file, line, the error name and description and msg, then abort if crash is true. | |
| bool | checkError (cudaError status, const char *func, const char *file, int line, bool crash=true, const char *msg="") |
| If status is not cudaSuccess, log file, line, the error name and description and msg, then abort if crash is true. | |
| template<typename T , int COLS = 16> | |
| static void | dumpGpuMem (CUdeviceptr devicePtr, size_t sizeInBytes, void *buf=nullptr, FILE *stream=stdout) |
| Dumps a buffer from the GPU to a stream. | |
| static void | show_buf (CUdeviceptr dptr, size_t size, CUstream stream=0) |
| Simple utility to display a device buffer. | |
| int | gpuMapHostFpgaMem (GpuDmaBuffer_t *outmem, int fd, uint64_t offset, size_t size) |
| Maps FPGA memory to the host and allows GPU access to it This is the "standard" way of doing DMA with CUDA. | |
| int | gpuMapFpgaMem (GpuDmaBuffer_t *outmem, int fd, uint64_t offset, size_t size, int write) |
| Maps GPU memory to the FPGA using RDMA This function uses gpuAddNvidiaMemory to give the FPGA access to some pages of memory located on the GPU. | |
| void | gpuUnmapFpgaMem (GpuDmaBuffer_t *mem) |
| Unmaps memory, clears out the pointer and size. | |
| int | gpuInitBufferState (GpuBufferState_t *b, int fd, size_t bufSize) |
| Allocates and inits buffer pairs on the GPU for RDMA operation. | |
| void | gpuDestroyBufferState (GpuBufferState_t *b) |
| Unmap and free both buffers of b with gpuUnmapFpgaMem(). | |
| struct | __attribute__ ((packed)) AxiWrDesc64_t |
| 64-bit write AXI descriptor data | |
| deviceFunc AxiWrDesc64_t | UnpackAxiWriteDescriptor (const void *data) |
| Return the 8 bytes at data as an AxiWrDesc64_t. | |
| DmaTgt_t | dmaTgtGet (const DataDev &) |
| Read the AXI stream demux select register of the GPU Async core and return TGT_CPU or TGT_GPU for its value, or TGT_ERR for any other value. | |
| void | dmaTgtSet (const DataDev &, DmaTgt_t) |
| Write tgt to the AXI stream demux select register of the GPU Async core; a write error is only reported with perror(). | |
| void | dmaIdxReset (const DataDev &) |
| Function to reset the DMA buffer round-robin index. | |
CUDA and GPU Async helpers (error checks, DataDev, CudaContext, FPGA and GPU memory mapping, DMA target selection, GPUTimer) from axi-pcie-devel.
In psdaq they are built only into the pgpread_gpu tool.
| #define chkError | ( | rc, | |
| ... | |||
| ) | checkError((rc), #rc, __FILE__, __LINE__, false, NOARG __VA_ARGS__) |
Check a CUDA driver or runtime result rc with checkError(), logging any failure with the optional message without aborting; evaluates to true on failure.
| #define chkFatal | ( | rc, | |
| ... | |||
| ) | checkError((rc), #rc, __FILE__, __LINE__, true, NOARG __VA_ARGS__) |
Check a CUDA driver or runtime result rc with checkError(), logging any failure with the optional message and aborting.
| #define deviceFunc |
This file is part of 'axi-pcie-devel'. It is subject to the license terms in the LICENSE.txt file found in the top-level directory of this distribution and at: https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. No part of 'axi-pcie-devel', including this file, may be copied, modified, propagated, or distributed except according to the terms contained in
| #define globalFunc |
Empty when not compiling with nvcc; global under nvcc.
| #define hostFunc |
Empty when not compiling with nvcc; host under nvcc.
| #define NOARG "" |
Empty string literal put in front of the optional message, so that the message argument is never empty (per the code comment).
| enum DmaTgt_t |
Functions to get and set the DMA destination.
| fd | The file descriptor of the PGP PCIe device |
| mode | The enumerated value of the destination |
| Enumerator | |
|---|---|
| TGT_CPU | Value 0: destination CPU. |
| TGT_GPU | Value 1: destination GPU. |
| TGT_ERR | Returned by dmaTgtGet() for any other register value. |
| struct __attribute__ | ( | (packed) | ) |
64-bit write AXI descriptor data
Overflow bit
Continue bit
| bool checkError | ( | cudaError | status, |
| const char * | func, | ||
| const char * | file, | ||
| int | line, | ||
| bool | crash = true, |
||
| const char * | msg = "" |
||
| ) |
If status is not cudaSuccess, log file, line, the error name and description and msg, then abort if crash is true.
Returns true on failure, else false; func is not used.
| bool checkError | ( | CUresult | status, |
| const char * | func, | ||
| const char * | file, | ||
| int | line, | ||
| bool | crash = true, |
||
| const char * | msg = "" |
||
| ) |
If status is not CUDA_SUCCESS, log file, line, the error name and description and msg, then abort if crash is true.
Returns true on failure, else false; func is not used.
| void dmaIdxReset | ( | const DataDev & | ) |
Function to reset the DMA buffer round-robin index.
| fd | The file descriptor of the PGP PCIe device |
Read the AXI stream demux select register of the GPU Async core and return TGT_CPU or TGT_GPU for its value, or TGT_ERR for any other value.
A read error is only reported with perror().
Write tgt to the AXI stream demux select register of the GPU Async core; a write error is only reported with perror().
|
inlinestatic |
Dumps a buffer from the GPU to a stream.
| devicePtr | Pointer to the block of memory to dump on the GPU |
| sizeInBytes | |
| buf | The copy buffer (assumed to be sizeInBytes in size). If NULL, one will be allocated |
| stream | The stream to dump to |
| void gpuDestroyBufferState | ( | GpuBufferState_t * | b | ) |
Unmap and free both buffers of b with gpuUnmapFpgaMem().
| int gpuInitBufferState | ( | GpuBufferState_t * | b, |
| int | fd, | ||
| size_t | bufSize | ||
| ) |
Allocates and inits buffer pairs on the GPU for RDMA operation.
| b | Buffer state to init |
| fd | The file descriptor of the DataDev device to allocate for |
| bufSize | The size of the buffers to allocate |
| int gpuMapFpgaMem | ( | GpuDmaBuffer_t * | outmem, |
| int | fd, | ||
| uint64_t | offset, | ||
| size_t | size, | ||
| int | write | ||
| ) |
Maps GPU memory to the FPGA using RDMA This function uses gpuAddNvidiaMemory to give the FPGA access to some pages of memory located on the GPU.
This is the other method of doing DMA, and it requires custom driver code and a very specific PCIe topology. Regardless, RDMA allows for low-latency, high-bandwidth DMA transfers between two devices on the bus, without needing to interact with the CPU.
| outmem | |
| fd | File descriptor of the FPGA device |
| offset | Offset of the register block |
| size | Size of the register block |
| write | If 1, this will be writable |
| int gpuMapHostFpgaMem | ( | GpuDmaBuffer_t * | outmem, |
| int | fd, | ||
| uint64_t | offset, | ||
| size_t | size | ||
| ) |
Maps FPGA memory to the host and allows GPU access to it This is the "standard" way of doing DMA with CUDA.
cuMemHostRegister essentially just gives CUDA access to some pages and allows the GPU to read/write to them. Unlike RDMA, this doesn't require any custom code on the kernel side, this will work with any (properly aligned) buffer given, whether it's IO memory or not. Again unlike RDMA, cuMemHostRegister has more latency and lower throughput, since a DMA transfer must occur between the GPU <-> HOST <-> FPGA
| outmem | |
| fd | File descriptor of the FPGA device |
| offset | Offset of the register block |
| size | Size of the register block |
| void gpuUnmapFpgaMem | ( | GpuDmaBuffer_t * | mem | ) |
Unmaps memory, clears out the pointer and size.
|
static |
Simple utility to display a device buffer.
|
inline |
Return the 8 bytes at data as an AxiWrDesc64_t.