Files
nvsci_samples/rawstream/rawstream_main.c
svcmobrel-release a3f1b7ea33 Updating prebuilts and/or headers
2eba699906039d6615aae4967f6ea79bfe44a40a - event_sample_app/block_pool.c
f3abb0a884f0647204ad32ff51255c4712e52120 - event_sample_app/Makefile
9ee49033e077ac5c8bf458a04c91dd3dbed9633d - event_sample_app/event_loop.h
b33adce6eb1bbc7af23f6c37b6a635479e18a66a - event_sample_app/block_returnsync.c
a56041c06b6bc1d3812b72b399d7d78dd7895485 - event_sample_app/block_limiter.c
ca34c957759f7a010f0cbbbf9bedc03a2c98092b - event_sample_app/block_c2c.c
8d6d0ec3aa8e374a1d2a5fedc9dd24ff7bbdb731 - event_sample_app/block_multicast.c
a76149a2531899e35843d939f60ad8979d8cf65f - event_sample_app/block_consumer_uc1.c
9da8763e4af4b4b7278507a3ebfe2c68a7a24585 - event_sample_app/util.h
2bf7e1383d6e8913c9b0a6a8bdd48fe63d8098d0 - event_sample_app/block_producer_uc1.c
a54abf82eaa2d888e379ab4596ba68ce264e80b5 - event_sample_app/block_info.h
080a6efe263be076c7046e70e31098c2bbed0f6d - event_sample_app/block_presentsync.c
7dd10e5ea71f0c4a09bbe1f9f148f67a13ee098c - event_sample_app/util.c
bc1a6f9017b28e5707c166a658a35e6b3986fdf4 - event_sample_app/usecase1.h
317f43efc59638bf1eae8303f0c79eafb059241a - event_sample_app/block_ipc.c
40361c8f0b68f7d5207db2466ce08c19c0bf1c90 - event_sample_app/event_loop_service.c
efad113d0107e5d8f90146f3102a7c0ed22f1a35 - event_sample_app/event_loop_threads.c
2908615cebcf36330b9850c57e8745bf324867b2 - event_sample_app/block_queue.c
36ed68eca1a7800cf0d94e763c9fc352ee8cda1e - event_sample_app/block_common.c
675f75d61bd0226625a8eaaf0e503c9e976c8d61 - event_sample_app/main.c
c3b26619dd07d221e953fc5dc29a50dcb95a8b97 - rawstream/Makefile
1fbb82e2281bb2e168c87fd20903bbed898ca160 - rawstream/rawstream_cuda.c
1d96498fe3c922f143f7e50e0a32b099714060ad - rawstream/rawstream_consumer.c
d077dafc9176686f6d081026225325c2a303a60e - rawstream/rawstream_producer.c
54ae655edddda7dcabe22fbf0b27c3f617978851 - rawstream/rawstream.h
d5ffeef3c7ad2af6f6f31385db7917b5ef9a7438 - rawstream/rawstream_ipc_linux.c
81e3d6f8ff5252797a7e9e170b74df6255f54f1b - rawstream/rawstream_main.c

Change-Id: I0f4e671693eb0addfe8d0e6532cc8f240cb6c778
2025-09-19 10:10:49 -07:00

231 lines
6.6 KiB
C

//! \file
//! \brief NvStreams rawstream main file.
//!
//! \copyright
//! SPDX-FileCopyrightText: Copyright (c) 2020-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//! SPDX-License-Identifier: LicenseRef-NvidiaProprietary
//!
//! NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
//! property and proprietary rights in and to this material, related
//! documentation and any modifications thereto. Any use, reproduction,
//! disclosure or distribution of this material and related documentation
//! without an express license agreement from NVIDIA CORPORATION or
//! its affiliates is strictly prohibited.
#include "rawstream.h"
#include <getopt.h>
NvSciSyncModule syncModule = NULL;
NvSciBufModule bufModule = NULL;
NvSciSyncAttrList producerSignalAttrs = NULL;
NvSciSyncAttrList consumerSignalAttrs = NULL;
NvSciSyncAttrList producerWaitAttrs = NULL;
NvSciSyncAttrList consumerWaitAttrs = NULL;
NvSciSyncAttrList prodToConsAttrs = NULL;
NvSciSyncAttrList consToProdAttrs = NULL;
NvSciSyncObj consumerSignalObj = NULL;
NvSciSyncObj producerSignalObj = NULL;
NvSciSyncObj consumerWaitObj = NULL;
NvSciSyncObj producerWaitObj = NULL;
NvSciBufAttrList producerWriteAttrs = NULL;
NvSciBufAttrList consumerReadAttrs = NULL;
NvSciBufAttrList combinedBufAttrs = NULL;
Buffer buffers[totalBuffers];
IpcWrapper ipcWrapper;
int late_attach = 0;
int main(int argc, char *argv[])
{
NvSciError err;
int producer;
const char* endpoint = "Unknown";
int ret = 0;
int opt;
producer = -1;
while ((opt = getopt(argc, argv, "pcl")) != -1) {
switch (opt) {
case 'p':
producer = 1;
endpoint = "Producer";
break;
case 'c':
producer = 0;
endpoint = "Consumer";
break;
case 'l':
late_attach = 1;
break;
default:
fprintf(stderr, "Unknown option: '%c'\n", opt);
}
}
if (producer == -1 || optind < argc) {
fprintf(stderr, "Usage: ./rawstream [-l] {-p or -c}\n");
fprintf(stderr,
"-p denotes producer, -c denotes consumer, -l denotes late-attach \n");
fprintf(stderr,
"either -p or -c should be provided, while -l is optional param\n");
return 1;
}
fprintf(stderr, "%p application starting\n", endpoint);
// Open sync module (shared by both all threads)
err = NvSciSyncModuleOpen(&syncModule);
if (NvSciError_Success != err) {
fprintf(stderr, "%s unable to open sync module (%x)\n",
endpoint, err);
return 1;
}
// Open buf module (shared by both all threads)
err = NvSciBufModuleOpen(&bufModule);
if (NvSciError_Success != err) {
fprintf(stderr, "%s unable to open buf module (%x)\n",
endpoint, err);
ret = 1;
goto close_sync_module;
}
// Initialize IPC library
err = NvSciIpcInit();
if (NvSciError_Success != err) {
fprintf(stderr, "%s unable to init ipc library (%x)\n",
endpoint, err);
ret = 1;
goto close_buf_module;
}
// Establish IPC communications based on endpoint
// TODO: Settle on final IPC channel names
if (producer == 1) {
err = ipcInit("nvscisync_a_0", &ipcWrapper);
} else {
err = ipcInit("nvscisync_a_1", &ipcWrapper);
}
if (NvSciError_Success != err) {
fprintf(stderr, "%s unable to initialize communication (%x)\n",
endpoint, err);
ret = 1;
goto deinit_IPC;
}
// Test communication by exchanging a simple handshake message
const int send_handshake = 12345;
err = ipcSend(&ipcWrapper, &send_handshake, sizeof(send_handshake));
if (NvSciError_Success != err) {
fprintf(stderr, "%s failed to send handshake (%x)\n",
endpoint, err);
ret = 1;
goto deinit_IPC;
}
int recv_handshake = 0;
ipcRecvFill(&ipcWrapper, &recv_handshake, sizeof(recv_handshake));
if (NvSciError_Success != err) {
fprintf(stderr, "%s failed to receive handshake (%x)\n",
endpoint, err);
ret = 1;
goto deinit_IPC;
}
if (send_handshake != recv_handshake) {
fprintf(stderr, "%s handshake did not match (%x)\n",
endpoint, err);
ret = 1;
goto deinit_IPC;
}
// Initialize buffer list
for (uint32_t i=0; i<totalBuffers; ++i) {
buffers[i].owner = 0;
buffers[i].fence = NvSciSyncFenceInitializer;
}
// Launch appropriate thread
if (producer == 1) {
// Launch producer threads
pthread_t producerThread;
if (0 != pthread_create(&producerThread, NULL, producerFunc, &ret)) {
fprintf(stderr, "Failed to launch producer\n");
ret = 1;
goto deinit_IPC;
}
// Wait for thread to finish
(void)pthread_join(producerThread, NULL);
} else {
// Launch consumer threads
pthread_t consumerThread;
if (0 != pthread_create(&consumerThread, NULL, consumerFunc, &ret)) {
fprintf(stderr, "Failed to launch consumer\n");
ret = 1;
goto deinit_IPC;
}
// Wait for thread to finish
(void)pthread_join(consumerThread, NULL);
}
deinit_IPC:
ipcDeinit(&ipcWrapper);
(void)NvSciIpcDeinit();
close_buf_module:
(void)NvSciBufModuleClose(bufModule);
close_sync_module:
(void)NvSciSyncModuleClose(syncModule);
fprintf(stderr, "Sample completed\n");
return ret;
}
// Checksum calculation
#define CRC32_POLYNOMIAL 0xEDB88320L
uint32_t GenerateCRC(uint8_t* data_ptr,
uint32_t height,
uint32_t width,
uint32_t pitch)
{
uint32_t y = 0U, x = 0U;
uint32_t crc = 0U, tmp;
static uint32_t crcTable[256];
static int initialized = 0;
//Initilaize CRC table, which is an one time operation
if (!initialized) {
for (int i = 0; i <= 255; i++) {
tmp = i;
for (int j = 8; j > 0; j--) {
if (tmp & 1) {
tmp = (tmp >> 1) ^ CRC32_POLYNOMIAL;
} else {
tmp >>= 1;
}
}
crcTable[i] = tmp;
}
initialized = 1;
}
//Calculate CRC for the data
for (y = 0U; y < height; y++) {
for (x = 0U; x < width; x++) {
tmp = (crc >> 8) & 0x00FFFFFFL;
crc = tmp ^ crcTable[((uint32_t) crc ^ *(data_ptr + x)) & 0xFF];
}
data_ptr += pitch;
}
return crc;
}