Files
nvsci_samples/rawstream/rawstream_main.c
svcmobrel-release 5d1819bced Updating prebuilts and/or headers
8193be73ce0a488f62034cb87083cdf09f52cd5d - event_sample_app/block_pool.c
a0bd135d707994a41ed3a4234b5f875a268fed4d - event_sample_app/Makefile
44f6de348f8bdd5cb584b3e8cc4b05e9482dddd2 - event_sample_app/event_loop.h
6ff0f1c2d7ef2e2fa9ece6fdc850b58b87207526 - event_sample_app/block_returnsync.c
1158201e78094e9e866fa99095c9ffc2ec9f5a27 - event_sample_app/block_limiter.c
f5e2aea98ba9264ee1068a700222dff8d5d5c7a4 - event_sample_app/block_c2c.c
ef057870dade9af70656b37340e9bcad35d49380 - event_sample_app/block_multicast.c
641e3634da873970b574b23a1024b2e7155b88ff - event_sample_app/block_consumer_uc1.c
ced622a41d1a48dcb23e6a1a02ae9640ef9b837c - event_sample_app/util.h
3a1013021a572887303fb6db245b5b01fe07e9a0 - event_sample_app/block_producer_uc1.c
dac99c442185b020fbdae07bfc1e7df78343eb83 - event_sample_app/block_info.h
b5dd68bec3ae6f9049aad1cb5a86c3db4af02e17 - event_sample_app/block_presentsync.c
e0861e9fe5d160d47d758464146d7192f9c70a5f - event_sample_app/util.c
d7e42e2b6088ff4596abc7256eb018d757a4021e - event_sample_app/usecase1.h
65ffe5af6ae6bc0418f348167c473849d4697e47 - event_sample_app/block_ipc.c
b52e34443ac441a9df48029de944aa0a50d1b101 - event_sample_app/event_loop_service.c
5001f036389a4f7952cb4974dd3323908208ca30 - event_sample_app/event_loop_threads.c
a71ed037f9d77d0944f40f54cf25db8180d007e2 - event_sample_app/block_queue.c
d6bbd17599543f1760d87851150a12a2a842a24d - event_sample_app/block_common.c
40f949c4c37ab4aa4a84182b345f3de6fceab39b - event_sample_app/main.c
458833ab233a725c067bf9b1fc60ef39872eee80 - rawstream/Makefile
1fbb82e2281bb2e168c87fd20903bbed898ca160 - rawstream/rawstream_cuda.c
e26c09f1ad1a3a7d2c29dae1b38d3fd90c23af6e - rawstream/rawstream_consumer.c
2bed038ca070aa5dccd6b672a98f093340e829bb - rawstream/rawstream_producer.c
3df4e5c00a3dc002ee9877e282bd28ffa87fa6f0 - rawstream/rawstream.h
d5ffeef3c7ad2af6f6f31385db7917b5ef9a7438 - rawstream/rawstream_ipc_linux.c
f28c1cd5fe26b6dc5930d5556b54364c9b91767c - rawstream/rawstream_main.c

Change-Id: I938f32e9d8445019e4585b3076bc6cac860f8a0f
2024-09-27 12:49:12 -07:00

210 lines
6.0 KiB
C

/*
* Copyright (c) 2020 NVIDIA Corporation. All Rights Reserved.
*
* NVIDIA Corporation and its licensors retain all intellectual property and
* proprietary rights in and to this software and related documentation. Any
* use, reproduction, disclosure or distribution of this software and related
* documentation without an express license agreement from NVIDIA Corporation
* is strictly prohibited.
*/
#include "rawstream.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 main(int argc, char *argv[])
{
NvSciError err;
int producer;
const char* endpoint;
int ret = 0;
if ((argc == 2) && (strcmp(argv[1], "-p") == 0)){
producer = 1;
endpoint = "Producer";
} else if ((argc == 2) && (strcmp(argv[1], "-c") == 0)) {
producer = 0;
endpoint = "Consumer";
} else {
fprintf(stderr,
"The usage of the app is ./rawstream followed by -p or -c\n");
fprintf(stderr,
" -p denotes producer and -c denotes consumer\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;
}