NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
dpa_initiator_target_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 #include "../common/dpa_initiator_target_common_defs.h"
30 
38 static uint32_t received_values[EXPECTED_NUM_RECEIVES] = {0};
39 
43 static uint32_t num_receive = 0;
44 
56 __dpa_global__ void thread1_kernel(uint64_t arg)
57 {
58  DOCA_DPA_DEV_LOG_INFO("%s: Hello from Thread #1\n", __func__);
59 
60  struct dpa_thread1_arg *thread_arg = (struct dpa_thread1_arg *)arg;
62  int found = 0;
63  uint64_t received_val = 0;
64  uint32_t user_data;
65 
66  if (thread_arg->dpa_ctx_handle) {
68  }
69 
70  DOCA_DPA_DEV_LOG_INFO("%s: Read completion info\n", __func__);
71  found = doca_dpa_dev_get_completion(thread_arg->dpa_comp_handle, &comp_element);
72  DOCA_DPA_DEV_LOG_INFO("%s: doca_dpa_dev_get_completion() returned %d\n", __func__, found);
73 
74  num_receive++;
75 
76  DOCA_DPA_DEV_LOG_INFO("%s: doca_dpa_dev_get_completion_type() returned %d\n",
77  __func__,
78  doca_dpa_dev_get_completion_type(comp_element));
79  DOCA_DPA_DEV_LOG_INFO("%s: doca_dpa_dev_get_completion_immediate() returned %u\n",
80  __func__,
82 
83  user_data = doca_dpa_dev_get_completion_user_data(comp_element);
84  DOCA_DPA_DEV_LOG_INFO("%s: doca_dpa_dev_get_completion_user_data() returned %u\n", __func__, user_data);
85 
86  received_val = *((uint64_t *)(thread_arg->local_buf_addr));
87  DOCA_DPA_DEV_LOG_INFO("%s: Value of DPA received buffer is %lu\n", __func__, received_val);
88  received_values[received_val - 1] = 1;
89 
91  for (uint32_t i = 0; i < EXPECTED_NUM_RECEIVES; i++) {
92  if (received_values[i] != 1) {
93  DOCA_DPA_DEV_LOG_ERR("%s: Thread #1 didn't receive data with value %u\n",
94  __func__,
95  (i + 1));
96  DOCA_DPA_DEV_LOG_INFO("%s: Finish\n", __func__);
98  }
99  }
100 
101  DOCA_DPA_DEV_LOG_INFO("%s: Received all data values, Notify Thread #2\n", __func__);
103 
104  DOCA_DPA_DEV_LOG_INFO("%s: Finish\n", __func__);
106  }
107 
108  DOCA_DPA_DEV_LOG_INFO("%s: Repost RDMA receive on DPA Mmap handle 0x%x, address 0x%lx, length %lu\n",
109  __func__,
110  thread_arg->dpa_mmap_handle,
111  thread_arg->local_buf_addr,
112  thread_arg->length);
114  thread_arg->dpa_mmap_handle,
115  thread_arg->local_buf_addr,
116  thread_arg->length);
117 
118  DOCA_DPA_DEV_LOG_INFO("%s: Acknowledge and request another notification\n", __func__);
121 
122  DOCA_DPA_DEV_LOG_INFO("%s: Reschedule\n", __func__);
124 }
125 
134 __dpa_global__ void thread2_kernel(uint64_t arg)
135 {
136  DOCA_DPA_DEV_LOG_INFO("%s: Hello from Thread #2\n", __func__);
137 
138  struct dpa_thread2_arg *thread2_arg = (struct dpa_thread2_arg *)arg;
139 
140  DOCA_DPA_DEV_LOG_INFO("%s: Set sync event value to %lu\n", __func__, thread2_arg->completion_count);
142 
143  DOCA_DPA_DEV_LOG_INFO("%s: Finish\n", __func__);
145 }
146 
160 __dpa_rpc__ uint64_t rdma_post_receive_rpc(doca_dpa_dev_t rdma_dpa_ctx_handle,
161  doca_dpa_dev_rdma_t target_rdma,
164  size_t length)
165 {
166  DOCA_DPA_DEV_LOG_INFO("%s: Target RDMA post receive on DPA Mmap handle 0x%x, address 0x%lx, length %lu\n",
167  __func__,
170  length);
171  if (rdma_dpa_ctx_handle) {
172  doca_dpa_dev_device_set(rdma_dpa_ctx_handle);
173  }
175 
176  return 0;
177 }
178 
193 __dpa_rpc__ uint64_t rdma_post_send_imm_rpc(doca_dpa_dev_t rdma_dpa_ctx_handle,
194  doca_dpa_dev_rdma_t rdma,
195  uint32_t connection_id,
198  size_t length,
199  uint32_t immediate)
200 {
202  "%s: Post RDMA send with connection_id %u, immediate %u on DPA Mmap handle 0x%x, address 0x%lx, length %lu\n",
203  __func__,
204  connection_id,
205  immediate,
208  length);
209  if (rdma_dpa_ctx_handle) {
210  doca_dpa_dev_device_set(rdma_dpa_ctx_handle);
211  }
213  connection_id,
216  length,
217  immediate,
219 
220  return 0;
221 }
uint32_t dpa_mmap_handle
#define EXPECTED_NUM_RECEIVES
Number of expected receive completions.
static uint32_t num_receive
Number of current receive completions.
__dpa_rpc__ uint64_t rdma_post_send_imm_rpc(doca_dpa_dev_t rdma_dpa_ctx_handle, doca_dpa_dev_rdma_t rdma, uint32_t connection_id, uintptr_t local_buf_addr, doca_dpa_dev_mmap_t dpa_mmap_handle, size_t length, uint32_t immediate)
RPC function to post RDMA send with immediate operation.
__dpa_global__ void thread2_kernel(uint64_t arg)
Kernel function for DPA thread #2.
__dpa_global__ void thread1_kernel(uint64_t arg)
Kernel function for DPA thread #1.
__dpa_rpc__ uint64_t rdma_post_receive_rpc(doca_dpa_dev_t rdma_dpa_ctx_handle, doca_dpa_dev_rdma_t target_rdma, doca_dpa_dev_uintptr_t local_buf_addr, doca_dpa_dev_mmap_t dpa_mmap_handle, size_t length)
RPC function to post first RDMA receive operation on target RDMA.
static uint32_t received_values[EXPECTED_NUM_RECEIVES]
Array used to mark received data when completion is received.
struct dpa_thread_arg __dpa_global__
DOCA_EXPERIMENTAL void doca_dpa_dev_rdma_post_send_imm(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 immediate, uint32_t flags)
Post an RDMA send with immediate operation.
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_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_completion_request_notification(doca_dpa_dev_completion_t dpa_comp_handle)
Request notification on the DPA completion.
DOCA_EXPERIMENTAL void doca_dpa_dev_thread_reschedule(void)
Reschedule a DPA thread.
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.
DOCA_EXPERIMENTAL void doca_dpa_dev_thread_notify(doca_dpa_dev_notification_completion_t comp_handle)
Notify the completion handle and trigger the attached thread.
DOCA_EXPERIMENTAL uint32_t doca_dpa_dev_get_completion_user_data(doca_dpa_dev_completion_element_t comp_element)
Get completion element user data.
#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 doca_dpa_dev_completion_type_t doca_dpa_dev_get_completion_type(doca_dpa_dev_completion_element_t comp_element)
Get completion element type.
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 uint32_t doca_dpa_dev_get_completion_immediate(doca_dpa_dev_completion_element_t comp_element)
Get completion element immediate data.
@ 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
uint64_t doca_dpa_dev_uintptr_t
DPA pointer type definition.
Definition: doca_dpa.h:78
uint32_t doca_dpa_dev_mmap_t
Handle on the DPA for a doca_mmap instance.
Definition: doca_mmap.h:74
uint64_t doca_dpa_dev_rdma_t
Definition: doca_rdma.h:79
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:298
DPA thread #1 device argument struct.
DPA thread #2 device argument struct.