123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
- /* auto generate by HHB_VERSION "1.13.x" */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdint.h>
- #include <libgen.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/mman.h>
- #include <pthread.h>
- #include <memory.h>
- #include "io.h"
- #include "shl_ref.h"
- #include "process_linker_types.h"
- #include "process_linker.h"
- #define FILE_LENGTH 1028
- #ifndef NULL
- #define NULL ((void *)0)
- #endif
- #define NUM_OF_BUFFERS 5
- #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \
- } while (0)
- int main(int argc, char **argv) {
- PlinkStatus sts = PLINK_STATUS_OK;
- PlinkPacket sendpkt, recvpkt;
- PlinkMsg msg;
- PlinkHandle plink = NULL;
- FILE *fp = NULL;
- int exitcode = 0;
- int i,j;
- uint64_t start_time, end_time;
- uint64_t _start_time, _end_time;
-
- int frames = 1000;
- int fd_mem = open("/dev/mem", O_RDWR | O_SYNC);
- if (fd_mem == -1) {
- printf("ERROR: failed to open: %s\n", "/dev/mem");
- return -1;
- }
- if (PLINK_create(&plink, "/tmp/plink_npu_featuremap.test", PLINK_MODE_CLIENT) != PLINK_STATUS_OK)
- errExit("Failed to create PLINK.");
- if (PLINK_connect(plink, NULL) != PLINK_STATUS_OK)
- errExit("Failed to connect to server.");
- int frmcnt = 0;
- // while loop to receive shm features
- do {
- sts = PLINK_recv(plink, 0, &recvpkt);
- for (i = 0; i < recvpkt.num; i++) {
- PlinkDescHdr *hdr = (PlinkDescHdr *)(recvpkt.list[i]);
- if (hdr->type == PLINK_TYPE_OBJECT) {
- PlinkObjectInfo *info = (PlinkObjectInfo *)(recvpkt.list[i]);
- printf("[G2D CLIENT] Received frame<%d> addr:<0x%08x>: face_cnt<%d>\n",
- info->header.id, info->bus_address, info->object_cnt);
- /* set input */
- char filename[FILE_LENGTH] = {0};
- uint8_t *vaddr = 0;
- start_time = shl_get_timespec();
- //printf("g2d_sink_test: wait frame%d\n", frmcnt);
- int size = info->object_cnt * sizeof(PlinkObjectDetect);
- vaddr = (uint8_t *) mmap(0, size, PROT_READ | PROT_WRITE,
- MAP_SHARED, fd_mem, info->bus_address);
- //printf("g2d_sink_test: get feature frame %d\n", index);
-
- end_time = shl_get_timespec();
- //printf("wait feature frame time: %.5fmsf\n", ((float)(end_time-start_time))/1000000);
- PlinkObjectDetect *face = (PlinkObjectDetect *)vaddr;
- for (j = 0; j < info->object_cnt; j++) {
- printf("feat[%d]: score<%f>, [%f,%f]~[%f,%f]\n", j,
- face[j].score,
- face[j].box.x1, face[j].box.y1,
- face[j].box.x2, face[j].box.y2);
- }
- // return the buffer to source
- msg.header.type = PLINK_TYPE_MESSAGE;
- msg.header.size = DATA_SIZE(PlinkMsg);
- msg.msg = hdr->id;
- sendpkt.list[0] = &msg;
- sendpkt.num = 1;
- sendpkt.fd = PLINK_INVALID_FD;
- if (PLINK_send(plink, 0, &sendpkt) == PLINK_STATUS_ERROR)
- errExit("Failed to send data.");
- //printf("g2d_sink_test: release frame%d\n", frmcnt);
-
- fprintf(stderr, "Run G2D frame time: %.5fms, FPS=%.2f\n", ((float)(end_time-start_time))/1000000,
- 1000000000.0/((float)(end_time-start_time)));
- }
- else if (hdr->type == PLINK_TYPE_MESSAGE)
- {
- PlinkMsg *msg = (PlinkMsg *)(recvpkt.list[i]);
- if (msg->msg == PLINK_EXIT_CODE)
- {
- exitcode = 1;
- printf("Exit\n");
- break;
- }
- }
- }
- if (recvpkt.fd != PLINK_INVALID_FD)
- close(recvpkt.fd);
- frmcnt++;
- #if 0
- if (frmcnt >= frames)
- {
- msg.header.type = PLINK_TYPE_MESSAGE;
- msg.header.size = DATA_SIZE(PlinkMsg);
- msg.msg = PLINK_EXIT_CODE;
- sendpkt.list[0] = &msg;
- sendpkt.num = 1;
- sendpkt.fd = PLINK_INVALID_FD;
- if (PLINK_send(plink, 0, &sendpkt) == PLINK_STATUS_ERROR)
- errExit("Failed to send data.");
- break;
- }
- #endif
- } while (exitcode == 0);
- cleanup:
- sleep(1); // Sleep one second to make sure server is ready for exit
- PLINK_close(plink, 0);
- if (fp != NULL)
- fclose(fp);
- return 0;
- }
|