NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
graph_sample.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <doca_mmap.h>
#include <doca_buf.h>
#include <doca_buf_inventory.h>
#include <doca_ctx.h>
#include <doca_pe.h>
#include <doca_dma.h>
#include <doca_graph.h>
#include <doca_types.h>
#include <doca_log.h>
#include <samples/common.h>
Include dependency graph for graph_sample.c:

Go to the source code of this file.

Data Structures

struct  graph_instance_data
 
struct  graph_sample_state
 

Macros

#define EXIT_ON_FAILURE(_expression_)
 
#define NUM_DMA_NODES   2
 
#define NUM_GRAPH_INSTANCES   10
 
#define DMA_BUFFER_SIZE   1024
 
#define REQUIRED_ENTRY_SIZE   (DMA_BUFFER_SIZE + (DMA_BUFFER_SIZE * NUM_DMA_NODES))
 
#define BUFFER_SIZE   (REQUIRED_ENTRY_SIZE * NUM_GRAPH_INSTANCES)
 
#define GRAPH_INSTANCE_NUM_BUFFERS   (1 + NUM_DMA_NODES)
 
#define BUF_INVENTORY_SIZE   (GRAPH_INSTANCE_NUM_BUFFERS * NUM_GRAPH_INSTANCES)
 

Functions

 DOCA_LOG_REGISTER (GRAPH::SAMPLE)
 
static doca_error_t allocate_buffer (struct graph_sample_state *state)
 
static doca_error_t check_dev_dma_capable (struct doca_devinfo *devinfo)
 
static doca_error_t open_device (struct graph_sample_state *state)
 
static doca_error_t create_pe (struct graph_sample_state *state)
 
static doca_error_t create_mmap (struct graph_sample_state *state)
 
static doca_error_t create_buf_inventory (struct graph_sample_state *state)
 
static void dma_task_completed_callback (struct doca_dma_task_memcpy *task, union doca_data task_user_data, union doca_data ctx_user_data)
 
static doca_error_t create_dma (struct graph_sample_state *state, uint32_t idx)
 
static doca_error_t create_dmas (struct graph_sample_state *state)
 
static doca_error_t start_contexts (struct graph_sample_state *state)
 
static void stop_contexts (struct graph_sample_state *state)
 
static doca_error_t user_node_callback (void *cookie)
 
static void destroy_graph_instance (struct graph_sample_state *state, uint32_t index)
 
static void graph_completion_callback (struct doca_graph_instance *graph_instance, union doca_data instance_user_data, union doca_data graph_user_data)
 
static doca_error_t create_graph (struct graph_sample_state *state)
 
static void destroy_graph (struct graph_sample_state *state)
 
static doca_error_t create_graph_instance (struct graph_sample_state *state, uint32_t index)
 
static doca_error_t create_graph_instances (struct graph_sample_state *state)
 
static void destroy_graph_instances (struct graph_sample_state *state)
 
static doca_error_t submit_instances (struct graph_sample_state *state)
 
static void poll_for_completion (struct graph_sample_state *state)
 
static void cleanup (struct graph_sample_state *state)
 
static doca_error_t run (struct graph_sample_state *state)
 
doca_error_t run_graph_sample (void)
 

Macro Definition Documentation

◆ BUF_INVENTORY_SIZE

#define BUF_INVENTORY_SIZE   (GRAPH_INSTANCE_NUM_BUFFERS * NUM_GRAPH_INSTANCES)

Definition at line 90 of file graph_sample.c.

◆ BUFFER_SIZE

#define BUFFER_SIZE   (REQUIRED_ENTRY_SIZE * NUM_GRAPH_INSTANCES)

Definition at line 86 of file graph_sample.c.

◆ DMA_BUFFER_SIZE

#define DMA_BUFFER_SIZE   1024

Definition at line 82 of file graph_sample.c.

◆ EXIT_ON_FAILURE

#define EXIT_ON_FAILURE (   _expression_)
Value:
{ \
doca_error_t _status_ = _expression_; \
if (_status_ != DOCA_SUCCESS) { \
DOCA_LOG_ERR("%s failed with status %s", __func__, doca_error_get_descr(_status_)); \
return _status_; \
} \
}
if(bitoffset % 64+bitlength > 64) result|
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_SUCCESS
Definition: doca_error.h:38

This sample creates the following graph:

    +-----+             +-----+
    | DMA |             | DMA |
    +--+--+             +-----+
       |                   |
       +---------+---------+
                 |
           +-----------+
           | User Node |
           +-----------+

The DMA nodes copy one source to two destinations. The user node compares the destinations to the source. The sample uses only one type of context to simplify the code, but a graph can use any context.

The sample runs 10 graph instances and uses polling to simplify the code. This macro is used to minimize code size. The macro runs an expression and returns error if the expression status is not DOCA_SUCCESS

Definition at line 68 of file graph_sample.c.

◆ GRAPH_INSTANCE_NUM_BUFFERS

#define GRAPH_INSTANCE_NUM_BUFFERS   (1 + NUM_DMA_NODES)

Definition at line 89 of file graph_sample.c.

◆ NUM_DMA_NODES

#define NUM_DMA_NODES   2

Definition at line 78 of file graph_sample.c.

◆ NUM_GRAPH_INSTANCES

#define NUM_GRAPH_INSTANCES   10

Definition at line 80 of file graph_sample.c.

◆ REQUIRED_ENTRY_SIZE

#define REQUIRED_ENTRY_SIZE   (DMA_BUFFER_SIZE + (DMA_BUFFER_SIZE * NUM_DMA_NODES))

Definition at line 84 of file graph_sample.c.

Function Documentation

◆ allocate_buffer()

static doca_error_t allocate_buffer ( struct graph_sample_state state)
static

Allocates a buffer that will be used for the source and destination buffers.

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 150 of file graph_sample.c.

◆ check_dev_dma_capable()

static doca_error_t check_dev_dma_capable ( struct doca_devinfo *  devinfo)
static

Definition at line 169 of file graph_sample.c.

◆ cleanup()

static void cleanup ( struct graph_sample_state state)
static

This method cleans up the sample resources in reverse order of their creation. This method does not check for destroy return values for simplify. Real code should check the return value and act accordingly.

@state [in]: sample state

Definition at line 612 of file graph_sample.c.

◆ create_buf_inventory()

static doca_error_t create_buf_inventory ( struct graph_sample_state state)
static

Create buffer inventory, initialize and start it.

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 229 of file graph_sample.c.

◆ create_dma()

static doca_error_t create_dma ( struct graph_sample_state state,
uint32_t  idx 
)
static

Create DMA

@state [in]: sample state @idx [in]: context index

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 265 of file graph_sample.c.

◆ create_dmas()

static doca_error_t create_dmas ( struct graph_sample_state state)
static

Create DMAs

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 288 of file graph_sample.c.

◆ create_graph()

static doca_error_t create_graph ( struct graph_sample_state state)
static

This method creates the graph. Creating a node adds it to the graph roots. Adding dependency removes a dependent node from the graph roots. The method creates all nodes and then adds the dependency out of convenience. Adding dependency during node creation is supported.

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 431 of file graph_sample.c.

◆ create_graph_instance()

static doca_error_t create_graph_instance ( struct graph_sample_state state,
uint32_t  index 
)
static

This method creates a graph instance Graph instance creation usually includes initializing the data for the nodes (e.g. initializing tasks).

@state [in]: sample state @index [in]: the graph instance index

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 487 of file graph_sample.c.

◆ create_graph_instances()

static doca_error_t create_graph_instances ( struct graph_sample_state state)
static

Create graph instances

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 545 of file graph_sample.c.

◆ create_mmap()

static doca_error_t create_mmap ( struct graph_sample_state state)
static

Create MMAP, initialize and start it.

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 210 of file graph_sample.c.

◆ create_pe()

static doca_error_t create_pe ( struct graph_sample_state state)
static

Creates a progress engine

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 195 of file graph_sample.c.

◆ destroy_graph()

static void destroy_graph ( struct graph_sample_state state)
static

Destroy the graph

@state [in]: sample state

Definition at line 470 of file graph_sample.c.

◆ destroy_graph_instance()

static void destroy_graph_instance ( struct graph_sample_state state,
uint32_t  index 
)
static

Destroy graph instance

@state [in]: sample state @index [in]: the graph instance index

Definition at line 373 of file graph_sample.c.

◆ destroy_graph_instances()

static void destroy_graph_instances ( struct graph_sample_state state)
static

Destroy graph instances

@state [in]: sample state

Definition at line 562 of file graph_sample.c.

◆ dma_task_completed_callback()

static void dma_task_completed_callback ( struct doca_dma_task_memcpy *  task,
union doca_data  task_user_data,
union doca_data  ctx_user_data 
)
static

DMA task completed callback

: This method is used as a mandatory input for the doca_dma_task_memcpy_set_conf but will never be called because task completion callbacks are not invoked when the task is submitted to a graph.

@task [in]: DMA task @task_user_data [in]: Task user data @ctx_user_data [in]: context user data

Definition at line 249 of file graph_sample.c.

◆ DOCA_LOG_REGISTER()

DOCA_LOG_REGISTER ( GRAPH::SAMPLE  )

◆ graph_completion_callback()

static void graph_completion_callback ( struct doca_graph_instance *  graph_instance,
union doca_data  instance_user_data,
union doca_data  graph_user_data 
)
static

This method processes a graph instance completion. The sample does not care if the instance was successful or failed and will act the same way on both cases.

@graph_instance [in]: completed graph instance @instance_user_data [in]: graph instance user data @graph_user_data [in]: graph user data

Definition at line 408 of file graph_sample.c.

◆ open_device()

static doca_error_t open_device ( struct graph_sample_state state)
static

Opens a device that supports DMA

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 180 of file graph_sample.c.

◆ poll_for_completion()

static void poll_for_completion ( struct graph_sample_state state)
static

Poll the work queue until all instances are completed

@state [in]: sample state

Definition at line 593 of file graph_sample.c.

◆ run()

static doca_error_t run ( struct graph_sample_state state)
static

Run the sample The method (and the method it calls) does not cleanup anything in case of failures. It assumes that cleanup is called after it at any case.

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 654 of file graph_sample.c.

◆ run_graph_sample()

doca_error_t run_graph_sample ( void  )

Run the graph sample

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 676 of file graph_sample.c.

◆ start_contexts()

static doca_error_t start_contexts ( struct graph_sample_state state)
static

Start contexts The method adds the device to the contexts, starts them and add them to the work queue.

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 305 of file graph_sample.c.

◆ stop_contexts()

static void stop_contexts ( struct graph_sample_state state)
static

Stop contexts The method removes the contexts from the work queue, stops them and removes the device from them.

@state [in]: sample state

Definition at line 323 of file graph_sample.c.

◆ submit_instances()

static doca_error_t submit_instances ( struct graph_sample_state state)
static

Submit graph instances

@state [in]: sample state

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 576 of file graph_sample.c.

◆ user_node_callback()

static doca_error_t user_node_callback ( void *  cookie)
static

User node callback This callback is called when the graph user node is executed. The callback compares the source buffer to the destination buffers.

@cookie [in]: callback cookie

Returns
: DOCA_SUCCESS on success and DOCA_ERROR otherwise

Definition at line 341 of file graph_sample.c.