NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
gpunetio_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #ifndef GPUNETIO_SEND_WAIT_TIME_COMMON_H_
27 #define GPUNETIO_SEND_WAIT_TIME_COMMON_H_
28 
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <signal.h>
34 
35 #include <cuda.h>
36 #include <cuda_runtime.h>
37 
38 #include <doca_error.h>
39 #include <doca_dev.h>
40 #include <doca_mmap.h>
41 #include <doca_gpunetio.h>
42 #include <doca_eth_rxq.h>
43 #include <doca_buf_array.h>
44 
45 #include "common.h"
46 
47 /* Set alignment to 64kB to work on all platforms */
48 #define GPU_PAGE_SIZE (1UL << 16)
49 #define MAX_PCI_ADDRESS_LEN 32U
50 #define CUDA_BLOCK_THREADS 32
51 #define PACKET_SIZE 1024
52 #define ETHER_ADDR_LEN 6
53 #define MAX_RQ_DESCR_NUM 8192
54 #define MAX_PKT_NUM 16384
55 #define MAX_PKT_SIZE 2048
56 #define MAX_RX_TIMEOUT_NS 500000 // 500us
57 #define MAX_RX_NUM_PKTS 2048
58 
59 /* Application configuration structure */
60 struct sample_send_wait_cfg {
61  char gpu_pcie_addr[MAX_PCI_ADDRESS_LEN]; /* GPU PCIe address */
62  char nic_pcie_addr[MAX_PCI_ADDRESS_LEN]; /* Network card PCIe address */
63 };
64 
65 /* Send queues objects */
66 struct rxq_queue {
67  struct doca_gpu *gpu_dev; /* GPUNetio handler associated to queues*/
68  struct doca_dev *ddev; /* DOCA device handler associated to queues */
69 
70  struct doca_ctx *eth_rxq_ctx; /* DOCA Ethernet send queue context */
71  struct doca_eth_rxq *eth_rxq_cpu; /* DOCA Ethernet send queue CPU handler */
72  struct doca_gpu_eth_rxq *eth_rxq_gpu; /* DOCA Ethernet send queue GPU handler */
73  struct doca_mmap *pkt_buff_mmap; /* DOCA mmap to receive packet with DOCA Ethernet queue */
74  void *gpu_pkt_addr; /* DOCA mmap GPU memory address */
75  int dmabuf_fd; /* GPU memory dmabuf descriptor */
76  struct doca_flow_port *port; /* DOCA Flow port */
77  struct doca_flow_pipe *rxq_pipe; /* DOCA Flow receive pipe */
78  struct doca_flow_pipe *root_pipe; /* DOCA Flow root pipe */
79  struct doca_flow_pipe_entry *root_udp_entry; /* DOCA Flow root entry */
80 };
81 
82 /*
83  * Launch GPUNetIO simple receive sample
84  *
85  * @sample_cfg [in]: Sample config parameters
86  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
87  */
89 
90 #if __cplusplus
91 extern "C" {
92 #endif
93 
94 /*
95  * Launch a CUDA kernel to send packets with wait on time feature.
96  *
97  * @stream [in]: CUDA stream to launch the kernel
98  * @rxq [in]: DOCA Eth Tx queue to use to send packets
99  * @gpu_exit_condition [in]: exit from CUDA kernel
100  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
101  */
102 doca_error_t kernel_receive_packets(cudaStream_t stream, struct rxq_queue *rxq, uint32_t *gpu_exit_condition);
103 
104 #if __cplusplus
105 }
106 #endif
107 #endif
doca_error_t kernel_receive_packets(cudaStream_t stream, struct rxq_queue *rxq, uint32_t *gpu_exit_condition)
doca_error_t gpunetio_simple_receive(struct sample_send_wait_cfg *sample_cfg)
#define MAX_PCI_ADDRESS_LEN
enum doca_error doca_error_t
DOCA API return codes.
struct doca_eth_rxq * eth_rxq_cpu
struct doca_dev * ddev
struct doca_gpu * gpu_dev
struct doca_mmap * pkt_buff_mmap
struct doca_flow_pipe_entry * root_udp_entry
struct doca_flow_port * port
struct doca_flow_pipe * rxq_pipe
struct doca_ctx * eth_rxq_ctx
void * gpu_pkt_addr
struct doca_flow_pipe * root_pipe
struct doca_gpu_eth_rxq * eth_rxq_gpu
char gpu_pcie_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]
char nic_pcie_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]