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_txq.h>
44 #include <doca_buf_array.h>
45 
46 #include "common.h"
47 
48 /* Set alignment to 64kB to work on all platforms */
49 #define GPU_PAGE_SIZE (1UL << 16)
50 #define MAX_PCI_ADDRESS_LEN 32U
51 #define PACKET_SIZE 1024
52 #define ETHER_ADDR_LEN 6
53 #define MAX_SQ_DESCR_NUM 8192
54 #define MAX_RX_TIMEOUT_NS 500000 // 500us
55 #define MAX_RX_NUM_PKTS 2048
56 
57 struct ether_hdr {
58  uint8_t d_addr_bytes[ETHER_ADDR_LEN]; /* Destination addr bytes in tx order */
59  uint8_t s_addr_bytes[ETHER_ADDR_LEN]; /* Source addr bytes in tx order */
60  uint16_t ether_type; /* Frame type */
61 } __attribute__((__packed__));
62 
63 /* Application configuration structure */
65  char gpu_pcie_addr[MAX_PCI_ADDRESS_LEN]; /* GPU PCIe address */
66  char nic_pcie_addr[MAX_PCI_ADDRESS_LEN]; /* Network card PCIe address */
67  uint32_t pkt_size; /* Packet size to send */
68  uint32_t cuda_threads; /* Number of CUDA threads in CUDA send kernel */
69 };
70 
71 /* Send queues objects */
72 struct txq_queue {
73  struct doca_gpu *gpu_dev; /* GPUNetio handler associated to queues*/
74  struct doca_dev *ddev; /* DOCA device handler associated to queues */
75 
76  struct doca_ctx *eth_txq_ctx; /* DOCA Ethernet send queue context */
77  struct doca_eth_txq *eth_txq_cpu; /* DOCA Ethernet send queue CPU handler */
78  struct doca_gpu_eth_txq *eth_txq_gpu; /* DOCA Ethernet send queue GPU handler */
79  struct doca_mmap *pkt_buff_mmap; /* DOCA mmap to send packet with DOCA Ethernet queue */
80  void *gpu_pkt_addr; /* DOCA mmap GPU memory address */
81  int dmabuf_fd; /* GPU memory dmabuf descriptor */
82  struct doca_flow_port *port; /* DOCA Flow port */
83  struct doca_buf_arr *buf_arr; /* DOCA buffer array object around GPU memory buffer */
84  struct doca_gpu_buf_arr *buf_arr_gpu; /* DOCA buffer array GPU handle */
85  uint32_t pkt_size; /* Packet size to send */
86  uint32_t cuda_threads; /* Number of CUDA threads in CUDA send kernel */
87  uint32_t inflight_sends; /* Number of inflight sends in queue */
88 };
89 
90 /*
91  * Launch GPUNetIO simple send sample
92  *
93  * @sample_cfg [in]: Sample config parameters
94  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
95  */
97 
98 #if __cplusplus
99 extern "C" {
100 #endif
101 
102 /*
103  * Launch a CUDA kernel to send packets with wait on time feature.
104  *
105  * @stream [in]: CUDA stream to launch the kernel
106  * @txq [in]: DOCA Eth Tx queue to use to send packets
107  * @gpu_exit_condition [in]: exit from CUDA kernel
108  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
109  */
110 doca_error_t kernel_send_packets(cudaStream_t stream, struct txq_queue *txq, uint32_t *gpu_exit_condition);
111 
112 #if __cplusplus
113 }
114 #endif
115 #endif
doca_error_t kernel_send_packets(cudaStream_t stream, struct txq_queue *txq, uint32_t *gpu_exit_condition)
struct sample_simple_send_cfg __attribute__
doca_error_t gpunetio_simple_send(struct sample_simple_send_cfg *sample_cfg)
#define ETHER_ADDR_LEN
#define MAX_PCI_ADDRESS_LEN
enum doca_error doca_error_t
DOCA API return codes.
uint8_t s_addr_bytes[ETHER_ADDR_LEN]
Definition: packets.h:62
uint8_t d_addr_bytes[ETHER_ADDR_LEN]
Definition: packets.h:61
uint16_t ether_type
Definition: packets.h:63
char nic_pcie_addr[MAX_PCI_ADDRESS_LEN]
char gpu_pcie_addr[MAX_PCI_ADDRESS_LEN]
void * gpu_pkt_addr
struct doca_buf_arr * buf_arr
struct doca_dev * ddev
uint32_t pkt_size
uint32_t inflight_sends
struct doca_gpu_eth_txq * eth_txq_gpu
uint32_t cuda_threads
struct doca_flow_port * port
struct doca_mmap * pkt_buff_mmap
struct doca_ctx * eth_txq_ctx
struct doca_gpu_buf_arr * buf_arr_gpu
struct doca_eth_txq * eth_txq_cpu
struct doca_gpu * gpu_dev