NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
gpunetio_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-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 
34 #include <cuda.h>
35 #include <cuda_runtime.h>
36 
37 #include <doca_error.h>
38 #include <doca_dev.h>
39 #include <doca_mmap.h>
40 #include <doca_gpunetio.h>
41 #include <doca_eth_txq.h>
42 #include <doca_buf_array.h>
43 
44 #include "common.h"
45 
46 /* Set alignment to 64kB to work on all platforms */
47 #define GPU_PAGE_SIZE (1UL << 16)
48 #define WARP_SIZE 32
49 #define NUM_BURST_SEND 8
50 #define NUM_PACKETS_X_BURST WARP_SIZE
51 #define PACKET_SIZE 1024
52 #define DELTA_NS 50000000 /* 50ms of delta before sending the first burst */
53 #define ETHER_ADDR_LEN 6
54 #define MAX_SQ_DESCR_NUM 8192
55 
56 /* Application configuration structure */
58  char gpu_pcie_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]; /* GPU PCIe address */
59  char nic_pcie_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]; /* Network card PCIe address */
60  uint32_t time_interval_ns; /* Nanoseconds between sends */
61 };
62 
63 /* Tx buffer, used to send HTTP responses */
64 struct tx_buf {
65  struct doca_gpu *gpu_dev; /* GPU device */
66  struct doca_dev *ddev; /* Network DOCA device */
67  uint32_t num_packets; /* Number of packets in the buffer */
68  uint32_t max_pkt_sz; /* Max size of each packet in the buffer */
69  uint32_t pkt_nbytes; /* Effective bytes in each packet */
70  uint8_t *gpu_pkt_addr; /* GPU memory address of the buffer */
71  struct doca_mmap *mmap; /* DOCA mmap around GPU memory buffer for the DOCA device */
72  struct doca_buf_arr *buf_arr; /* DOCA buffer array object around GPU memory buffer */
73  struct doca_gpu_buf_arr *buf_arr_gpu; /* DOCA buffer array GPU handle */
74  int dmabuf_fd; /* GPU memory dmabuf file descriptor */
75 };
76 
77 /* Send queues objects */
78 struct txq_queue {
79  struct doca_gpu *gpu_dev; /* GPUNetio handler associated to queues*/
80  struct doca_dev *ddev; /* DOCA device handler associated to queues */
81 
82  struct doca_ctx *eth_txq_ctx; /* DOCA Ethernet send queue context */
83  struct doca_eth_txq *eth_txq_cpu; /* DOCA Ethernet send queue CPU handler */
84  struct doca_gpu_eth_txq *eth_txq_gpu; /* DOCA Ethernet send queue GPU handler */
85 
86  struct tx_buf txbuf; /* GPU memory buffer for HTTP index page */
87 };
88 
89 struct ether_hdr {
90  uint8_t d_addr_bytes[ETHER_ADDR_LEN]; /* Destination addr bytes in tx order */
91  uint8_t s_addr_bytes[ETHER_ADDR_LEN]; /* Source addr bytes in tx order */
92  uint16_t ether_type; /* Frame type */
93 } __attribute__((__packed__));
94 
95 /*
96  * Launch GPUNetIO send wait on time sample
97  *
98  * @sample_cfg [in]: Sample config parameters
99  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
100  */
102 
103 #if __cplusplus
104 extern "C" {
105 #endif
106 
107 /*
108  * Launch a CUDA kernel to send packets with wait on time feature.
109  *
110  * @stream [in]: CUDA stream to launch the kernel
111  * @txq [in]: DOCA Eth Tx queue to use to send packets
112  * @intervals_gpu [in]: at which time each burst of packet must be sent
113  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
114  */
115 doca_error_t kernel_send_wait_on_time(cudaStream_t stream, struct txq_queue *txq, uint64_t *intervals_gpu);
116 
117 #if __cplusplus
118 }
119 #endif
120 #endif
doca_error_t gpunetio_send_wait_time(struct sample_send_wait_cfg *sample_cfg)
doca_error_t kernel_send_wait_on_time(cudaStream_t stream, struct txq_queue *txq, uint64_t *intervals_gpu)
#define ETHER_ADDR_LEN
struct sample_simple_send_cfg __attribute__
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
Definition: doca_dev.h:313
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 gpu_pcie_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]
char nic_pcie_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]
Definition: common.h:120
struct doca_mmap * mmap
Definition: common.h:127
struct doca_buf_arr * buf_arr
Definition: common.h:128
uint32_t pkt_nbytes
Definition: common.h:125
struct doca_gpu_buf_arr * buf_arr_gpu
Definition: common.h:129
uint8_t * gpu_pkt_addr
Definition: common.h:126
uint32_t max_pkt_sz
Definition: common.h:124
int dmabuf_fd
Definition: common.h:130
struct doca_dev * ddev
Definition: common.h:122
uint32_t num_packets
Definition: common.h:123
struct doca_gpu * gpu_dev
Definition: common.h:121
struct tx_buf txbuf
struct doca_dev * ddev
struct doca_gpu_eth_txq * eth_txq_gpu
struct doca_ctx * eth_txq_ctx
struct doca_eth_txq * eth_txq_cpu
struct doca_gpu * gpu_dev