NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
dpa_ping_pong_kernels_dev.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 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 #include <doca_dpa_dev.h>
27 #include <doca_dpa_dev_rdma.h>
28 #include <doca_dpa_dev_buf.h>
29 
30 #include "../common/dpa_ping_pong_common_defs.h"
31 
42 __dpa_global__ void thread_kernel(uint64_t arg)
43 {
44  struct dpa_thread_arg *thread_arg = (struct dpa_thread_arg *)arg;
46  int found = 0;
48  uint32_t *received_values = (uint32_t *)tls->received_values_arr_ptr;
49 
50  if (thread_arg->dpa_ctx_handle) {
52  }
53 
54  while (1) {
55  found = doca_dpa_dev_get_completion(thread_arg->dpa_comp_handle, &comp_element);
56  if (!found) {
57  continue;
58  }
59 
60  tls->num_receives++;
61  received_values[*((uint64_t *)(thread_arg->recv_addr))] = 1;
62 
64  thread_arg->recv_addr_mmap_handle,
65  thread_arg->recv_addr,
66  thread_arg->recv_addr_length);
67 
68  /* for the Ping DPA thread:
69  * the first post send was done at the RPC and therefore we need to update the send addr
70  * before the next post send in order to send values 0, 1, 2...
71  */
72  if (tls->is_ping_thread) {
73  (*((uint64_t *)(thread_arg->send_addr)))++;
74  }
75 
77  0,
78  thread_arg->send_addr_mmap_handle,
79  thread_arg->send_addr,
80  thread_arg->send_addr_length,
82 
83  DOCA_DPA_DEV_LOG_INFO("%s --> %s Iteration #%u\n",
84  (tls->is_ping_thread ? "Ping" : "Pong"),
85  (!tls->is_ping_thread ? "Ping" : "Pong"),
86  tls->num_receives);
87 
88  if (tls->num_receives == EXPECTED_NUM_RECEIVES) {
89  for (uint32_t i = 0; i < EXPECTED_NUM_RECEIVES; i++) {
90  if (received_values[i] != 1) {
91  DOCA_DPA_DEV_LOG_ERR("%s DPA Thread didn't receive data with value %u\n",
92  (tls->is_ping_thread ? "Ping" : "Pong"),
93  i);
95  }
96  }
97 
99  thread_arg->comp_sync_event_val);
101  }
102 
103  /* for the Pong DPA thread:
104  * the first post send was done at the kernel itself and therefore we need to update the send addr
105  * after the kernel's post send in order to send values 0, 1, 2...
106  */
107  if (!tls->is_ping_thread) {
108  (*((uint64_t *)(thread_arg->send_addr)))++;
109  }
110 
112  }
113 
115 }
116 
130 __dpa_rpc__ uint64_t trigger_first_iteration_rpc(doca_dpa_dev_t rdma_dpa_ctx_handle,
131  struct dpa_thread_arg ping_thread_arg,
132  struct dpa_thread_arg pong_thread_arg)
133 {
134  DOCA_DPA_DEV_LOG_INFO("Trigger First Ping --> Pong Iteration\n");
135 
136  if (rdma_dpa_ctx_handle) {
137  doca_dpa_dev_device_set(rdma_dpa_ctx_handle);
138  }
139 
141  ping_thread_arg.recv_addr_mmap_handle,
142  ping_thread_arg.recv_addr,
143  ping_thread_arg.recv_addr_length);
144 
146  pong_thread_arg.recv_addr_mmap_handle,
147  pong_thread_arg.recv_addr,
148  pong_thread_arg.recv_addr_length);
149 
151  0,
152  ping_thread_arg.send_addr_mmap_handle,
153  ping_thread_arg.send_addr,
154  ping_thread_arg.send_addr_length,
156 
157  return 0;
158 }
#define EXPECTED_NUM_RECEIVES
Number of expected receive completions.
static uint32_t received_values[EXPECTED_NUM_RECEIVES]
Array used to mark received data when completion is received.
struct dpa_thread_arg __dpa_global__
__dpa_rpc__ uint64_t trigger_first_iteration_rpc(doca_dpa_dev_t rdma_dpa_ctx_handle, struct dpa_thread_arg ping_thread_arg, struct dpa_thread_arg pong_thread_arg)
RPC function to trigger first ping pong send/receive iteration.
__dpa_global__ void thread_kernel(uint64_t arg)
Kernel function of DPA thread.
if(bitoffset % 64+bitlength > 64) result|
DOCA_EXPERIMENTAL void doca_dpa_dev_rdma_post_receive(doca_dpa_dev_rdma_t rdma, doca_dpa_dev_mmap_t mmap_handle, uint64_t addr, size_t length)
Post an RDMA receive operation.
DOCA_EXPERIMENTAL void doca_dpa_dev_rdma_post_send(doca_dpa_dev_rdma_t rdma, uint32_t connection_id, doca_dpa_dev_mmap_t mmap_handle, uint64_t addr, size_t length, uint32_t flags)
Post an RDMA send operation.
DOCA_EXPERIMENTAL void doca_dpa_dev_sync_event_update_set(doca_dpa_dev_sync_event_t dpa_dev_se_handle, uint64_t value)
Set the counter of a DOCA Sync Event to a given value.
DOCA_EXPERIMENTAL void doca_dpa_dev_device_set(doca_dpa_dev_t dpa_handle)
Set a DPA device.
DOCA_EXPERIMENTAL void doca_dpa_dev_thread_finish(void)
Finish a DPA thread.
#define DOCA_DPA_DEV_LOG_ERR(...)
Generate a DOCA DPA device ERROR log message.
Definition: doca_dpa_dev.h:271
DOCA_EXPERIMENTAL void doca_dpa_dev_completion_ack(doca_dpa_dev_completion_t dpa_comp_handle, uint64_t num_comp)
Acknowledge that the completions have been read on the completion context.
__dpa_global__ typedef uint64_t doca_dpa_dev_completion_element_t
DPA completion element handle type definition.
Definition: doca_dpa_dev.h:77
#define DOCA_DPA_DEV_LOG_INFO(...)
Generate a DOCA DPA device INFO log message.
Definition: doca_dpa_dev.h:287
DOCA_EXPERIMENTAL int doca_dpa_dev_get_completion(doca_dpa_dev_completion_t dpa_comp_handle, doca_dpa_dev_completion_element_t *comp_element)
Get DPA completion element.
DOCA_EXPERIMENTAL doca_dpa_dev_uintptr_t doca_dpa_dev_thread_get_local_storage(void)
Get DPA thread local storage.
@ DOCA_DPA_DEV_SUBMIT_FLAG_OPTIMIZE_REPORTS
Definition: doca_dpa_dev.h:113
@ DOCA_DPA_DEV_SUBMIT_FLAG_FLUSH
Definition: doca_dpa_dev.h:106
uint64_t doca_dpa_dev_t
DPA context handle type definition.
Definition: doca_dpa.h:73
DPA Thread local storage struct.
DPA thread device argument struct.