From 5af9fe5bba9f81c27c4c86e69fa45781256fe6a9 Mon Sep 17 00:00:00 2001 From: Dongju Chae Date: Fri, 9 Aug 2019 16:00:19 +0900 Subject: [PATCH] [Build/Dir] Reconstruct core source directory This commit reconstructs core source directory. The below is the summary of what's changed. 1. reconstruct src directory (issue #153), like +-- src/ | +-- host/ | +-- core/ | +-- ne-*.c/ne-*.h | +-- ip/ | +-- gem/ | +-- npu/ | +-- test/ | +-- unittests/ | +-- apptests/ 2. change meson.build scripts to keep the same style. 3. change source file names to have the same prefix. It resolves #153. Signed-off-by: Dongju Chae --- meson.build | 14 - meson_options.txt | 2 +- packaging/npu-engine.spec | 3 +- src/{core/npu-engine/ip => }/README.md | 0 src/core/{libgem-core => gem}/GEMdrvAPI.c | 0 src/core/{libgem-core => gem}/GEMdrvAPI.h | 0 src/core/{npu-engine => gem}/README.md | 0 src/core/gem/meson.build | 6 + src/core/{libnpu-core => ip}/README.md | 0 src/core/ip/meson.build | 4 + .../ip/plugin-ip-comm.c => ip/plugin-comm-ip.c} | 2 +- src/core/libgem-core/meson.build | 14 - src/core/libnpu-core/meson.build | 13 - src/core/libutils-core/meson.build | 16 - src/core/{npu-engine => }/main.c | 0 src/core/meson.build | 52 ++- src/core/{npu-engine => }/ne-armplugin.c | 0 src/core/{npu-engine => }/ne-comm.h | 0 src/core/{npu-engine => }/ne-common.h | 0 src/core/{libutils-core => }/ne-conf.c | 0 src/core/{libutils-core => }/ne-conf.h | 0 src/core/{npu-engine => }/ne-handler.c | 0 src/core/{npu-engine => }/ne-handler.h | 0 src/core/{npu-engine => }/ne-host-input-service.c | 0 src/core/{npu-engine => }/ne-inf.c | 0 src/core/{npu-engine => }/ne-inf.h | 0 src/core/{npu-engine => }/ne-inputservice.h | 0 src/core/{npu-engine => }/ne-mem.c | 0 src/core/{npu-engine => }/ne-mem.h | 0 src/core/{npu-engine => }/ne-model.h | 0 src/core/{npu-engine => }/ne-scheduler.c | 0 src/core/{npu-engine => }/ne-scheduler.h | 0 src/core/{libutils-core => }/ne-utils.c | 0 src/core/{libutils-core => }/ne-utils.h | 0 src/core/npu-engine/fm/meson.build | 5 - src/core/npu-engine/fm/plugin-fastmodel.c | 420 --------------------- src/core/npu-engine/ip/meson.build | 12 - src/core/npu-engine/meson.build | 60 --- src/core/npu-engine/usb/meson.build | 1 - src/core/{libnpu-core => npu}/NPUdrvAPI.c | 0 src/core/{libnpu-core => npu}/NPUdrvAPI.h | 0 src/core/{libgem-core => npu}/README.md | 0 src/core/npu/meson.build | 6 + src/host/libnpuhost/meson.build | 3 + src/host/meson.build | 2 + src/meson.build | 20 + src/test/apptests/meson.build | 1 + src/test/meson.build | 64 +--- src/test/unittests/meson.build | 67 ++++ .../ne_core_gem_test.cpp} | 10 +- .../ne_core_mem_test.cpp} | 14 +- .../ne_core_npu_test.cpp} | 8 +- .../ne_core_utils_test.cpp} | 6 +- 53 files changed, 182 insertions(+), 643 deletions(-) rename src/{core/npu-engine/ip => }/README.md (100%) rename src/core/{libgem-core => gem}/GEMdrvAPI.c (100%) rename src/core/{libgem-core => gem}/GEMdrvAPI.h (100%) rename src/core/{npu-engine => gem}/README.md (100%) create mode 100644 src/core/gem/meson.build rename src/core/{libnpu-core => ip}/README.md (100%) create mode 100644 src/core/ip/meson.build rename src/core/{npu-engine/ip/plugin-ip-comm.c => ip/plugin-comm-ip.c} (99%) delete mode 100644 src/core/libgem-core/meson.build delete mode 100644 src/core/libnpu-core/meson.build delete mode 100644 src/core/libutils-core/meson.build rename src/core/{npu-engine => }/main.c (100%) rename src/core/{npu-engine => }/ne-armplugin.c (100%) rename src/core/{npu-engine => }/ne-comm.h (100%) rename src/core/{npu-engine => }/ne-common.h (100%) rename src/core/{libutils-core => }/ne-conf.c (100%) rename src/core/{libutils-core => }/ne-conf.h (100%) rename src/core/{npu-engine => }/ne-handler.c (100%) rename src/core/{npu-engine => }/ne-handler.h (100%) rename src/core/{npu-engine => }/ne-host-input-service.c (100%) rename src/core/{npu-engine => }/ne-inf.c (100%) rename src/core/{npu-engine => }/ne-inf.h (100%) rename src/core/{npu-engine => }/ne-inputservice.h (100%) rename src/core/{npu-engine => }/ne-mem.c (100%) rename src/core/{npu-engine => }/ne-mem.h (100%) rename src/core/{npu-engine => }/ne-model.h (100%) rename src/core/{npu-engine => }/ne-scheduler.c (100%) rename src/core/{npu-engine => }/ne-scheduler.h (100%) rename src/core/{libutils-core => }/ne-utils.c (100%) rename src/core/{libutils-core => }/ne-utils.h (100%) delete mode 100644 src/core/npu-engine/fm/meson.build delete mode 100644 src/core/npu-engine/fm/plugin-fastmodel.c delete mode 100644 src/core/npu-engine/ip/meson.build delete mode 100644 src/core/npu-engine/meson.build delete mode 100644 src/core/npu-engine/usb/meson.build rename src/core/{libnpu-core => npu}/NPUdrvAPI.c (100%) rename src/core/{libnpu-core => npu}/NPUdrvAPI.h (100%) rename src/core/{libgem-core => npu}/README.md (100%) create mode 100644 src/core/npu/meson.build create mode 100644 src/test/apptests/meson.build create mode 100644 src/test/unittests/meson.build rename src/test/{libgem_test.cpp => unittests/ne_core_gem_test.cpp} (94%) rename src/test/{ne_mem_test.cpp => unittests/ne_core_mem_test.cpp} (98%) rename src/test/{npu_api_test.cpp => unittests/ne_core_npu_test.cpp} (96%) rename src/test/{ne_utils_test.cpp => unittests/ne_core_utils_test.cpp} (95%) diff --git a/meson.build b/meson.build index e5bf8f7..756bdff 100644 --- a/meson.build +++ b/meson.build @@ -50,20 +50,6 @@ iniparser_dep = dependency('iniparser') # iniparser library subdir('src') -comm_opt = get_option('comm_opt') - -if comm_opt == 'ip' - ne_dependencies = [ - npu_engine_dep - ] - - # Build final exported so - plugin_ip_executable = shared_library('npu-engine', - dependencies: ne_dependencies, - install : true, - install_dir: ne_libdir) -endif - # Set configuration to install .ini ne_install_conf = configuration_data() diff --git a/meson_options.txt b/meson_options.txt index df19b21..9b721b8 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,4 +1,4 @@ -option('comm_opt', type : 'combo', choices : ['ip', 'fm'], value : 'ip') +option('comm_opt', type : 'string', value : 'ip') option('resv_mem_size', type : 'string', value : '512M') option('working_dir', type : 'string', value : '/tmp/') option('log_dir', type : 'string', value : '/tmp') diff --git a/packaging/npu-engine.spec b/packaging/npu-engine.spec index b2619fd..e761a80 100644 --- a/packaging/npu-engine.spec +++ b/packaging/npu-engine.spec @@ -67,7 +67,7 @@ DESTDIR=%{buildroot} ninja install -C build %{?_smp_mflags} # Perform unit tests %check %if 0%{?unit_test} - pushd build/src/test + pushd build/src/test/unittests find . -maxdepth 1 -type f -perm 0755 -print0 | while IFS= read -r -d $'\0' unittest_exec; do %if 0%{?use_valgrind} %ifarch x86_64 @@ -114,6 +114,7 @@ DESTDIR=%{buildroot} ninja install -C build %{?_smp_mflags} %files %%defattr(-,root,root,-) %{_libdir}/libnpu-engine.so +%{_libdir}/libnpu-engine.a %{_sysconfdir}/npu-engine.ini %package devel diff --git a/src/core/npu-engine/ip/README.md b/src/README.md similarity index 100% rename from src/core/npu-engine/ip/README.md rename to src/README.md diff --git a/src/core/libgem-core/GEMdrvAPI.c b/src/core/gem/GEMdrvAPI.c similarity index 100% rename from src/core/libgem-core/GEMdrvAPI.c rename to src/core/gem/GEMdrvAPI.c diff --git a/src/core/libgem-core/GEMdrvAPI.h b/src/core/gem/GEMdrvAPI.h similarity index 100% rename from src/core/libgem-core/GEMdrvAPI.h rename to src/core/gem/GEMdrvAPI.h diff --git a/src/core/npu-engine/README.md b/src/core/gem/README.md similarity index 100% rename from src/core/npu-engine/README.md rename to src/core/gem/README.md diff --git a/src/core/gem/meson.build b/src/core/gem/meson.build new file mode 100644 index 0000000..3622ef0 --- /dev/null +++ b/src/core/gem/meson.build @@ -0,0 +1,6 @@ +ne_core_gem_inc = include_directories('.') +ne_core_gem_src = ['GEMdrvAPI.c'] +ne_core_gem_dep = declare_dependency( + sources : ne_core_gem_src, + dependencies : [libdrm_dep, ne_core_utils_dep], + include_directories : ne_core_gem_inc) diff --git a/src/core/libnpu-core/README.md b/src/core/ip/README.md similarity index 100% rename from src/core/libnpu-core/README.md rename to src/core/ip/README.md diff --git a/src/core/ip/meson.build b/src/core/ip/meson.build new file mode 100644 index 0000000..f08debd --- /dev/null +++ b/src/core/ip/meson.build @@ -0,0 +1,4 @@ +ne_plugin_comm_ip_src = ['plugin-comm-ip.c'] +ne_plugin_comm_dep = declare_dependency( + sources : ne_plugin_comm_ip_src, + include_directories : [ne_common_inc, ne_host_inc, ne_core_inc]) diff --git a/src/core/npu-engine/ip/plugin-ip-comm.c b/src/core/ip/plugin-comm-ip.c similarity index 99% rename from src/core/npu-engine/ip/plugin-ip-comm.c rename to src/core/ip/plugin-comm-ip.c index 2258de5..b8d0cd3 100644 --- a/src/core/npu-engine/ip/plugin-ip-comm.c +++ b/src/core/ip/plugin-comm-ip.c @@ -5,7 +5,7 @@ * Copyright (C) 2019 Parichay Kapoor */ /** - * @file plugin-ip-comm.c + * @file plugin-comm-ip.c * @date 26 Jul 2019 * @brief Implement API to access NPU from Host * @see http://suprem.sec.samsung.net/confluence/display/ODLC/Software+Stack diff --git a/src/core/libgem-core/meson.build b/src/core/libgem-core/meson.build deleted file mode 100644 index e7ebebd..0000000 --- a/src/core/libgem-core/meson.build +++ /dev/null @@ -1,14 +0,0 @@ -libgem_src = ['GEMdrvAPI.c'] -libgem_inc = include_directories('.') -libgem_dependencies = [libdrm_dep, libutils_dep] - -# Build library (static) -libgem_build = static_library('gem-core', - libgem_src, - dependencies: libgem_dependencies, - install: false -) - -# Declare dependency for other modules -libgem_dep = declare_dependency(link_with : libgem_build, - include_directories : libgem_inc) diff --git a/src/core/libnpu-core/meson.build b/src/core/libnpu-core/meson.build deleted file mode 100644 index b3c09bb..0000000 --- a/src/core/libnpu-core/meson.build +++ /dev/null @@ -1,13 +0,0 @@ -libnpucore_src = ['NPUdrvAPI.c'] -libnpucore_inc = include_directories('.') - -# Build library (static) -libnpucore = static_library('npu-core', - libnpucore_src, - include_directories: ne_common_inc, - dependencies: libutils_dep, - install : false) - -# Declare dependency for other modules -libnpucore_dep = declare_dependency(link_with : libnpucore, - include_directories: [ne_common_inc, libnpucore_inc]) diff --git a/src/core/libutils-core/meson.build b/src/core/libutils-core/meson.build deleted file mode 100644 index 51a0a16..0000000 --- a/src/core/libutils-core/meson.build +++ /dev/null @@ -1,16 +0,0 @@ -libutils_inc = include_directories('.') -libutils_src = [ - 'ne-conf.c', - 'ne-utils.c' -] - -# Build library (static) -libutils = static_library('libutils', - libutils_src, - include_directories: libutils_inc, - dependencies: iniparser_dep, - install : false) - -# Declare dependency for other modules -libutils_dep = declare_dependency(link_with : libutils, - include_directories: libutils_inc) diff --git a/src/core/npu-engine/main.c b/src/core/main.c similarity index 100% rename from src/core/npu-engine/main.c rename to src/core/main.c diff --git a/src/core/meson.build b/src/core/meson.build index 3f27ca3..fcf2eda 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -1,4 +1,48 @@ -subdir('libutils-core') -subdir('libgem-core') -subdir('libnpu-core') -subdir('npu-engine') +# Headers +ne_core_inc = include_directories('.') + +# Dependencies +ne_core_dependencies = [ + libm_dep, + thread_dep +] + +# Sources +ne_core_sources = [ + 'ne-host-input-service.c', + 'ne-handler.c', + 'ne-scheduler.c', + 'ne-inf.c', + 'ne-mem.c' +] + +ne_core_utils_sources = [ + 'ne-conf.c', + 'ne-utils.c', +] + +# Dependency for utils +ne_core_utils_dep = declare_dependency( + sources : ne_core_utils_sources, + dependencies : iniparser_dep, + include_directories : ne_core_inc +) +ne_core_dependencies += [ne_core_utils_dep] + +# Dependency for driver APIs +subdir('npu') +subdir('gem') + +ne_core_dependencies += [ne_core_npu_dep, ne_core_gem_dep] + +# Dependency for plugin comm. +comm_opt = get_option('comm_opt') +subdir(comm_opt) + +ne_core_dependencies += [ne_plugin_comm_dep] + +# Declare dependency for npu engine core +ne_core_dep = declare_dependency( + sources : ne_core_sources, + dependencies : ne_core_dependencies +) diff --git a/src/core/npu-engine/ne-armplugin.c b/src/core/ne-armplugin.c similarity index 100% rename from src/core/npu-engine/ne-armplugin.c rename to src/core/ne-armplugin.c diff --git a/src/core/npu-engine/ne-comm.h b/src/core/ne-comm.h similarity index 100% rename from src/core/npu-engine/ne-comm.h rename to src/core/ne-comm.h diff --git a/src/core/npu-engine/ne-common.h b/src/core/ne-common.h similarity index 100% rename from src/core/npu-engine/ne-common.h rename to src/core/ne-common.h diff --git a/src/core/libutils-core/ne-conf.c b/src/core/ne-conf.c similarity index 100% rename from src/core/libutils-core/ne-conf.c rename to src/core/ne-conf.c diff --git a/src/core/libutils-core/ne-conf.h b/src/core/ne-conf.h similarity index 100% rename from src/core/libutils-core/ne-conf.h rename to src/core/ne-conf.h diff --git a/src/core/npu-engine/ne-handler.c b/src/core/ne-handler.c similarity index 100% rename from src/core/npu-engine/ne-handler.c rename to src/core/ne-handler.c diff --git a/src/core/npu-engine/ne-handler.h b/src/core/ne-handler.h similarity index 100% rename from src/core/npu-engine/ne-handler.h rename to src/core/ne-handler.h diff --git a/src/core/npu-engine/ne-host-input-service.c b/src/core/ne-host-input-service.c similarity index 100% rename from src/core/npu-engine/ne-host-input-service.c rename to src/core/ne-host-input-service.c diff --git a/src/core/npu-engine/ne-inf.c b/src/core/ne-inf.c similarity index 100% rename from src/core/npu-engine/ne-inf.c rename to src/core/ne-inf.c diff --git a/src/core/npu-engine/ne-inf.h b/src/core/ne-inf.h similarity index 100% rename from src/core/npu-engine/ne-inf.h rename to src/core/ne-inf.h diff --git a/src/core/npu-engine/ne-inputservice.h b/src/core/ne-inputservice.h similarity index 100% rename from src/core/npu-engine/ne-inputservice.h rename to src/core/ne-inputservice.h diff --git a/src/core/npu-engine/ne-mem.c b/src/core/ne-mem.c similarity index 100% rename from src/core/npu-engine/ne-mem.c rename to src/core/ne-mem.c diff --git a/src/core/npu-engine/ne-mem.h b/src/core/ne-mem.h similarity index 100% rename from src/core/npu-engine/ne-mem.h rename to src/core/ne-mem.h diff --git a/src/core/npu-engine/ne-model.h b/src/core/ne-model.h similarity index 100% rename from src/core/npu-engine/ne-model.h rename to src/core/ne-model.h diff --git a/src/core/npu-engine/ne-scheduler.c b/src/core/ne-scheduler.c similarity index 100% rename from src/core/npu-engine/ne-scheduler.c rename to src/core/ne-scheduler.c diff --git a/src/core/npu-engine/ne-scheduler.h b/src/core/ne-scheduler.h similarity index 100% rename from src/core/npu-engine/ne-scheduler.h rename to src/core/ne-scheduler.h diff --git a/src/core/libutils-core/ne-utils.c b/src/core/ne-utils.c similarity index 100% rename from src/core/libutils-core/ne-utils.c rename to src/core/ne-utils.c diff --git a/src/core/libutils-core/ne-utils.h b/src/core/ne-utils.h similarity index 100% rename from src/core/libutils-core/ne-utils.h rename to src/core/ne-utils.h diff --git a/src/core/npu-engine/fm/meson.build b/src/core/npu-engine/fm/meson.build deleted file mode 100644 index 067beff..0000000 --- a/src/core/npu-engine/fm/meson.build +++ /dev/null @@ -1,5 +0,0 @@ -plugin_fm_inc = include_directories('.') -plugin_fm_sources = ['plugin-fastmodel.c'] -plugin_fm_dep = declare_dependency( - sources : plugin_fm_sources, - include_directories : plugin_fm_inc) diff --git a/src/core/npu-engine/fm/plugin-fastmodel.c b/src/core/npu-engine/fm/plugin-fastmodel.c deleted file mode 100644 index d5fe585..0000000 --- a/src/core/npu-engine/fm/plugin-fastmodel.c +++ /dev/null @@ -1,420 +0,0 @@ -/** - * Proprietary - * Copyright (C) 2019 Samsung Electronics - * Copyright (C) 2019 Dongju Chae - */ -/** - * @file plugin-fastmodel.c - * @date 29 Jul 2019 - * @brief NPU Engine's communication plugin for FastModel (N12) - * @see http://suprem.sec.samsung.net/confluence/display/ODLC/Software+Stack - * @see http://suprem.sec.samsung.net/confluence/pages/viewpage.action?pageId=128465352 - * @author Dongju Chae - * @bug No known bugs except for NYI items - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -/** @todo change this */ -#define SERVER_FM_ADDR "127.0.0.1" -#define SERVER_FM_INPUT_PORT 5515 -#define SERVER_FM_OUTPUT_PORT 5516 - -/** @brief recv/send macros for TCP/IP */ -#define RECV(fd, buf, size) (read(fd, buf, size) == size) -#define SEND(fd, buf, size) (write(fd, buf, size) == size) - -/** - * @note This retrieves model files and input frames from the host server via a TCP/IP comm. - * But, actual USB communications will work in the opposite way. - */ - -/** @brief command enum */ -typedef enum { - COMM_NONE = 0, - COMM_REGISTER, - COMM_UNREGISTER, - COMM_NEW_INPUT, - COMM_SET_OPMODE, -} n12_command; - -/** @brief n12's private data structure */ -typedef struct { - const hostHandlerInfo *handler; - int running; - int sockfd; - pthread_t comm_thread, output_thread; - pthread_mutex_t mutex; -} n12_private; - -static n12_private priv; - -/** @brief internal thread for sending output data via TCP/IP */ -static void* -run_output (void *data) -{ - pthread_mutex_lock (&priv.mutex); - - while (priv.running) { - struct sockaddr_in server_addr; - int sockfd, err = 0; - buffer *output_buffer; - hwmem *output_hwmem; - void *ptr; - - pthread_mutex_unlock (&priv.mutex); - - output_buffer = priv.handler->getCurrentOutputBuffer (&err); - if (err != 0) { - fprintf (stderr, "Fail to get output buffer (errno: %d)\n", err); - break; - } - - err = buffer_get_hwmem (output_buffer, &output_hwmem); - if (err != 0) { - GET_MEM()->return_buffer (output_buffer); - fprintf (stderr, "Fail to get hwmem (errno: %d)\n", err); - break; - } - - err = hwmem_get_data (output_hwmem, &ptr); - if (err != 0) { - GET_MEM()->return_buffer (output_buffer); - fprintf (stderr, "Fail to get data pointer (errno: %d)\n", err); - break; - } - - if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - GET_MEM()->return_buffer (output_buffer); - fprintf (stderr, "Fail to create a socket\n"); - break; - } - - memset (&server_addr, '\x00', sizeof (server_addr)); - - server_addr.sin_family = AF_INET; - server_addr.sin_port = htons(SERVER_FM_OUTPUT_PORT); - server_addr.sin_addr.s_addr = inet_addr(SERVER_FM_ADDR); - - if (connect (sockfd, (struct sockaddr *) &server_addr, sizeof (server_addr)) < 0) { - fprintf (stderr, "Fail to connect the server (%s:%d)\n", - SERVER_FM_ADDR, SERVER_FM_OUTPUT_PORT); - GET_MEM()->return_buffer (output_buffer); - close (sockfd); - break; - } - - if (!SEND (sockfd, ptr, output_hwmem->size)) { - fprintf (stderr, "Fail to send output data %lu\n", output_hwmem->size); - GET_MEM()->return_buffer (output_buffer); - close (sockfd); - break; - } - - GET_MEM()->return_buffer (output_buffer); - close (sockfd); - - pthread_mutex_lock (&priv.mutex); - } - pthread_mutex_unlock (&priv.mutex); - - return NULL; -} - -static int -handle_register (void) -{ - uint64_t data_size; - hwmem *hwmem; - void *ptr; - int err = 0; - - /* recv meta data */ - if (!RECV (priv.sockfd, &data_size, sizeof (data_size))) { - fprintf (stderr, "Fail to receive data size\n"); - err = -errno; - goto out; - } - - if (priv.handler->getAvailableModelMemory() < data_size) { - fprintf (stderr, "No availabl memory size\n"); - err = -ENOMEM; - goto out; - } - - if ((err = GET_MEM()->alloc (data_size, &hwmem)) != 0) { - fprintf (stderr, "Fail to allocate memory with size %lu\n", data_size); - goto out; - } - - if ((err = hwmem_activate (hwmem)) != 0) { - fprintf (stderr, "Fail to activate hwmem\n"); - goto out_free; - } - - if ((err = hwmem_get_data (hwmem, &ptr)) != 0) { - fprintf (stderr, "Fail to get data pointer\n"); - goto out_deactivate; - } - - if (!RECV (priv.sockfd, ptr, data_size)) { - fprintf (stderr, "Fail to receive data\n"); - err = -errno; - goto out_deactivate; - } - - if ((err = priv.handler->registerModel (hwmem)) != 0) { - fprintf (stderr, "Fail to registermodel\n"); - goto out_deactivate; - } - - return 0; - -out_deactivate: - hwmem_deactivate (hwmem); -out_free: - GET_MEM()->dealloc (hwmem); -out: - return err; -} - -static int -handle_unregister (void) -{ - uint64_t model_id, model_version; - - if (!RECV (priv.sockfd, &model_id, sizeof (model_id))) { - fprintf (stderr, "Fail to receive model id\n"); - return -errno; - } - - if (!RECV (priv.sockfd, &model_version, sizeof (model_version))) { - fprintf (stderr, "Fail to receive model version\n"); - return -errno; - } - - return priv.handler->unregisterModel (model_id, model_version); -} - -static int -handle_new_input (void) -{ - uint64_t data_size; - buffer *buffer; - hwmem *hwmem; - void *ptr; - int err = 0; - - buffer = priv.handler->getCurrentInputBuffer (&err); - if (err != 0) { - fprintf (stderr, "Fail to get input buffer (errno: %d)\n", err); - goto out; - } - - if ((err = buffer_get_hwmem (buffer, &hwmem)) != 0) { - GET_MEM()->return_buffer (buffer); - fprintf (stderr, "Fail to get hwmem (errno: %d)\n", err); - goto out; - } - - if ((err = hwmem_get_data (hwmem, &ptr)) != 0) { - GET_MEM()->return_buffer (buffer); - fprintf (stderr, "Fail to get data pointer (errno: %d)\n", err); - goto out; - } - - /* recv meta data */ - if (!RECV (priv.sockfd, &data_size, sizeof (data_size))) { - fprintf (stderr, "Fail to receive data size\n"); - err = -errno; - goto out; - } - - if (!RECV (priv.sockfd, ptr, data_size)) { - fprintf (stderr, "Fail to receive input data\n"); - err = -errno; - goto out; - } - - if ((err = priv.handler->validateBuffer (buffer)) != 0) { - fprintf (stderr, "Fail to validate buffer\n"); - goto out; - } - - return 0; -out: - return err; -} - -static void -n1_cb (buffer *buf, uint64_t offset, uint64_t size, void *data) -{ - /** @todo */ -} - -static int -handle_set_opmode (void) -{ - npu_input_opmode op; - int force; - uint64_t model_id, model_version; - - if (!RECV (priv.sockfd, &op, sizeof (op))) { - fprintf (stderr, "Fail to receive npu input opmode\n"); - return -errno; - } - - if (!RECV (priv.sockfd, &force, sizeof (force))) { - fprintf (stderr, "Fail to receive force variable\n"); - return -errno; - } - - if (!RECV (priv.sockfd, &model_id, sizeof (model_id))) { - fprintf (stderr, "Fail to receive model id\n"); - return -errno; - } - - if (!RECV (priv.sockfd, &model_version, sizeof (model_version))) { - fprintf (stderr, "Fail to receive model version\n"); - return -errno; - } - - return priv.handler->setOpMode (op, force, model_id, model_version, n1_cb, NULL /* TBD */); -} - -static void -raise_error (void) -{ - pthread_mutex_lock (&priv.mutex); - priv.running = 0; - pthread_mutex_unlock (&priv.mutex); -} - -/** @brief internal thread for reading command/input data via TCP/IP */ -static void* -run_comm (void *data) -{ - n12_command command; - int status; - - if (pthread_create (&priv.output_thread, NULL, run_output, (void*) NULL) < 0) { - fprintf (stderr, "Fail to create the internal output thread\n"); - goto out; - } - - pthread_mutex_lock (&priv.mutex); - while (priv.running) { - pthread_mutex_unlock (&priv.mutex); - - if (!RECV (priv.sockfd, &command, sizeof (n12_command))) { - fprintf (stderr, "Fail to receive command\n"); - raise_error (); - break; - } - - switch (command) { - case COMM_REGISTER: - if (handle_register () != 0) - raise_error (); - break; - case COMM_UNREGISTER: - if (handle_unregister () != 0) - raise_error (); - break; - case COMM_NEW_INPUT: - if (handle_new_input () != 0) - raise_error (); - break; - case COMM_SET_OPMODE: - if (handle_set_opmode () != 0) - raise_error (); - default: - raise_error (); - } - - pthread_mutex_lock (&priv.mutex); - } - pthread_mutex_unlock (&priv.mutex); - - pthread_join (priv.output_thread, (void **)&status); -out: - close (priv.sockfd); - - return NULL; -} - -/** @brief init function for fastmodel plugin */ -int -initNEcomm (const hostHandlerInfo *hh) -{ - struct sockaddr_in server_addr; - int sockfd; - - if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - fprintf (stderr, "Fail to create a socket\n"); - return -errno; - } - - memset (&server_addr, '\x00', sizeof (server_addr)); - - server_addr.sin_family = AF_INET; - server_addr.sin_port = htons(SERVER_FM_INPUT_PORT); - server_addr.sin_addr.s_addr = inet_addr(SERVER_FM_ADDR); - - if (connect (sockfd, (struct sockaddr *)&server_addr, sizeof (server_addr)) < 0) { - fprintf (stderr, "Fail to connect the server (%s:%d)\n", - SERVER_FM_ADDR, SERVER_FM_INPUT_PORT); - return -errno; - } - - priv.sockfd = sockfd; - priv.handler = hh; - priv.running = 1; - - pthread_mutex_init (&priv.mutex, NULL); - - if (pthread_create (&priv.comm_thread, NULL, run_comm, (void*) NULL) < 0) { - fprintf (stderr, "Fail to create the internal thread\n"); - close (sockfd); - priv.running = 0; - pthread_mutex_destroy (&priv.mutex); - return -errno; - } - - return 0; -} - -/** @brief exit function for fastmodel plugin */ -int -exitNEcomm (void) -{ - if (priv.running == 1) { - int status; - - pthread_mutex_lock (&priv.mutex); - priv.running = 0; - pthread_mutex_unlock (&priv.mutex); - - pthread_join (priv.comm_thread, (void*)&status); - pthread_mutex_destroy (&priv.mutex);; - } - - return 0; -} diff --git a/src/core/npu-engine/ip/meson.build b/src/core/npu-engine/ip/meson.build deleted file mode 100644 index 1cf0934..0000000 --- a/src/core/npu-engine/ip/meson.build +++ /dev/null @@ -1,12 +0,0 @@ -plugin_ip_sources = [] -plugin_ip_common_sources = ['plugin-ip-comm.c'] - -foreach s : plugin_ip_common_sources - plugin_ip_sources += join_paths(meson.current_source_dir(), s) -endforeach - -# Declare dependency -plugin_ip_src_dep = declare_dependency( - sources : plugin_ip_sources, - include_directories: [ne_common_inc, ne_host_inc, npu_engine_inc] -) diff --git a/src/core/npu-engine/meson.build b/src/core/npu-engine/meson.build deleted file mode 100644 index c003fa7..0000000 --- a/src/core/npu-engine/meson.build +++ /dev/null @@ -1,60 +0,0 @@ -npu_engine_sources = [] - -# Dependencies -npu_engine_dependencies = [ - libm_dep, - thread_dep, - libutils_dep, - libnpucore_dep, - libgem_dep -] - -# Sources -npu_engine_common_sources = [ - 'ne-host-input-service.c', - 'ne-handler.c', - 'ne-scheduler.c', - 'ne-inf.c', - 'ne-mem.c', -] - -# Headers -npu_engine_inc = include_directories('.') - -foreach s : npu_engine_common_sources - npu_engine_sources += join_paths(meson.current_source_dir(), s) -endforeach - -comm_opt = get_option('comm_opt') - -# Build executable -if comm_opt == 'fm' - subdir('fm') - npu_engine_dependencies += [plugin_fm_dep] - # Declare dependency - npu_engine_dep = declare_dependency( - sources : npu_engine_common_sources, - include_directories : ne_common_inc, - dependencies : npu_engine_dependencies - ) - - npu_engine_executable = executable('npu-engine-test', - sources : join_paths(meson.current_source_dir(), 'main.c'), - include_directories : ne_common_inc, - dependencies : npu_engine_dependencies) - -else # ip comm - subdir('ip') - npu_engine_dependencies += [plugin_ip_src_dep] - - npu_engine_build = static_library('npu-engine-common', - npu_engine_sources, - include_directories : ne_common_inc, - dependencies: npu_engine_dependencies, - install : false) - - # Declare dependency for other modules - npu_engine_dep = declare_dependency(link_with : npu_engine_build, - include_directories : [ne_common_inc, npu_engine_inc], - dependencies : npu_engine_dependencies) -endif diff --git a/src/core/npu-engine/usb/meson.build b/src/core/npu-engine/usb/meson.build deleted file mode 100644 index 6607342..0000000 --- a/src/core/npu-engine/usb/meson.build +++ /dev/null @@ -1 +0,0 @@ -# DO NOTHING, YET diff --git a/src/core/libnpu-core/NPUdrvAPI.c b/src/core/npu/NPUdrvAPI.c similarity index 100% rename from src/core/libnpu-core/NPUdrvAPI.c rename to src/core/npu/NPUdrvAPI.c diff --git a/src/core/libnpu-core/NPUdrvAPI.h b/src/core/npu/NPUdrvAPI.h similarity index 100% rename from src/core/libnpu-core/NPUdrvAPI.h rename to src/core/npu/NPUdrvAPI.h diff --git a/src/core/libgem-core/README.md b/src/core/npu/README.md similarity index 100% rename from src/core/libgem-core/README.md rename to src/core/npu/README.md diff --git a/src/core/npu/meson.build b/src/core/npu/meson.build new file mode 100644 index 0000000..8225a19 --- /dev/null +++ b/src/core/npu/meson.build @@ -0,0 +1,6 @@ +ne_core_npu_inc = include_directories('.') +ne_core_npu_src = ['NPUdrvAPI.c'] +ne_core_npu_dep = declare_dependency( + sources : ne_core_npu_src, + dependencies : ne_core_utils_dep, + include_directories : [ne_common_inc, ne_core_npu_inc]) diff --git a/src/host/libnpuhost/meson.build b/src/host/libnpuhost/meson.build index 2a5ddb4..8cf91da 100644 --- a/src/host/libnpuhost/meson.build +++ b/src/host/libnpuhost/meson.build @@ -1,2 +1,5 @@ +## This is not used in the current design (i.e., NPU-IP). +## The function in libnpuhost are implemented in /src/core/ip/plugin-comm-ip.c + libnpuhost_inc = include_directories('.') libnpuhost_dep = declare_dependency(include_directories: libnpuhost_inc) diff --git a/src/host/meson.build b/src/host/meson.build index 7a39a98..ee5139f 100644 --- a/src/host/meson.build +++ b/src/host/meson.build @@ -1 +1,3 @@ subdir('libnpuhost') + +ne_host_dep = [libnpuhost_dep] diff --git a/src/meson.build b/src/meson.build index 31c349f..dc9ed8d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,3 +1,23 @@ subdir('core') subdir('host') + +# Final dependencies +ne_dependencies = [ + ne_core_dep, + ne_host_dep # not used yet +] + +# Build library +ne_library_static = static_library('npu-engine', + include_directories : ne_common_inc, + dependencies: ne_dependencies, + install : true, + install_dir : ne_libdir) +ne_library_shared = shared_library('npu-engine', + include_directories : ne_common_inc, + dependencies: ne_dependencies, + install : true, + install_dir : ne_libdir) + +# Build tests subdir('test') diff --git a/src/test/apptests/meson.build b/src/test/apptests/meson.build new file mode 100644 index 0000000..5a253c8 --- /dev/null +++ b/src/test/apptests/meson.build @@ -0,0 +1 @@ +## For app tests, make build executables which links with 'ne_library_shared' diff --git a/src/test/meson.build b/src/test/meson.build index e509787..7d5fe4d 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -1,62 +1,2 @@ -# C++ may be enabled inside test because this is not supposed to be installed in NPU-Core machine for deployment. -# However, try not to contaminate other parts of core with C++ dependencies. - -add_languages('cpp') - -gtest_dep = dependency('gtest', required: false) -if gtest_dep.found() - libgem_unittest_deps = [ - libgem_dep, - gtest_dep - ] - - unittest_libgem = executable('unittest_libgem', - ['libgem_test.cpp'], - dependencies: [libgem_unittest_deps], - cpp_args : '-std=c++11', - install : true, - install_dir : join_paths(ne_bindir, 'unittests') - ) - - test('unittest_libgem', unittest_libgem) - - libnpu_unittest_deps = [ - libnpucore_dep, - gtest_dep - ] - - unittest_libnpu = executable('unittest_libnpu', - ['npu_api_test.cpp'], - dependencies: [libnpu_unittest_deps], - cpp_args : '-std=c++11', - install : true, - install_dir : join_paths(ne_bindir, 'unittests') - ) - - test('unittest_libnpu', unittest_libnpu) - - npu_engine_unittest_deps = [ - npu_engine_dep, - gtest_dep - ] - - unittest_ne_mem = executable('unittest_ne_mem', - ['ne_mem_test.cpp'], - dependencies: [npu_engine_unittest_deps], - cpp_args : '-std=c++11', - install : true, - install_dir : join_paths(ne_bindir, 'unittests') - ) - - test('unittest_ne_mem', unittest_ne_mem) - - unittest_ne_utils = executable('unittest_ne_utils', - ['ne_utils_test.cpp'], - dependencies: [npu_engine_unittest_deps], - cpp_args : '-std=c++11', - install : true, - install_dir : join_paths(ne_bindir, 'unittests') - ) - - test('unittest_ne_utils', unittest_ne_utils) -endif +subdir('unittests') +subdir('apptests') diff --git a/src/test/unittests/meson.build b/src/test/unittests/meson.build new file mode 100644 index 0000000..907f75b --- /dev/null +++ b/src/test/unittests/meson.build @@ -0,0 +1,67 @@ +# C++ may be enabled inside test because this is not supposed to be installed in NPU-Core machine for deployment. +# However, try not to contaminate other parts of core with C++ dependencies. + +add_languages('cpp') + +gtest_dep = dependency('gtest', required: false) +if gtest_dep.found() + ne_core_gem_unittest_deps = [ + ne_core_gem_dep, + gtest_dep + ] + + unittest_ne_core_gem = executable('unittest_ne_core_gem', + ['ne_core_gem_test.cpp'], + dependencies: [ne_core_gem_unittest_deps], + cpp_args : '-std=c++11', + install : true, + install_dir : join_paths(ne_bindir, 'unittests') + ) + + test('unittest_ne_core_gem', unittest_ne_core_gem) + + ne_core_npu_unittest_deps = [ + ne_core_npu_dep, + gtest_dep + ] + + unittest_ne_core_npu = executable('unittest_ne_core_npu', + ['ne_core_npu_test.cpp'], + dependencies: [ne_core_npu_unittest_deps], + cpp_args : '-std=c++11', + install : true, + install_dir : join_paths(ne_bindir, 'unittests') + ) + + test('unittest_ne_core_npu', unittest_ne_core_npu) + + ne_core_utils_unittest_deps = [ + ne_core_utils_dep, + gtest_dep + ] + + unittest_ne_core_utils = executable('unittest_ne_core_utils', + ['ne_core_utils_test.cpp'], + dependencies: [ne_core_utils_unittest_deps], + cpp_args : '-std=c++11', + install : true, + install_dir : join_paths(ne_bindir, 'unittests') + ) + + test('unittest_ne_core_utils', unittest_ne_core_utils) + + ne_core_unittest_deps = [ + ne_core_dep, + gtest_dep + ] + + unittest_ne_core_mem = executable('unittest_ne_core_mem', + ['ne_core_mem_test.cpp'], + dependencies: [ne_core_unittest_deps], + cpp_args : '-std=c++11', + install : true, + install_dir : join_paths(ne_bindir, 'unittests') + ) + + test('unittest_ne_core_mem', unittest_ne_core_mem) +endif diff --git a/src/test/libgem_test.cpp b/src/test/unittests/ne_core_gem_test.cpp similarity index 94% rename from src/test/libgem_test.cpp rename to src/test/unittests/ne_core_gem_test.cpp index 1a9011e..4abe74f 100644 --- a/src/test/libgem_test.cpp +++ b/src/test/unittests/ne_core_gem_test.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2019 Dongju Chae */ /** - * @file libgem_test.cpp + * @file ne_core_gem_test.cpp * @date 30 Jun 2019 * @brief UnitTests to test functions in libgem-core * @author Dongju Chae @@ -26,7 +26,7 @@ extern "C" /** * @brief subtest function testing 'gem_open' */ -TEST (test_gem, open) +TEST (ne_core_gem_test, open) { int fd = gem_open(GEM_NAME); @@ -41,7 +41,7 @@ TEST (test_gem, open) /** * @brief subtest function testing 'gem_create/destroy' */ -TEST (test_gem, create) +TEST (ne_core_gem_test, create) { int fd = gem_open(GEM_NAME); uint32_t size; @@ -70,7 +70,7 @@ TEST (test_gem, create) /** * @brief subtest function testing 'gem_mmap' */ -TEST (test_gem, mmap) +TEST (ne_core_gem_test, mmap) { uint32_t handle, size, page; uint32_t *ptr; @@ -100,7 +100,7 @@ TEST (test_gem, mmap) /** * @brief subtest function testing to export a gem buffer and mmap for dmabuf */ -TEST (test_gem, export_dmabuf) +TEST (ne_core_gem_test, export_dmabuf) { uint32_t handle, size, page; uint32_t *ptr; diff --git a/src/test/ne_mem_test.cpp b/src/test/unittests/ne_core_mem_test.cpp similarity index 98% rename from src/test/ne_mem_test.cpp rename to src/test/unittests/ne_core_mem_test.cpp index 44783ef..9f3c812 100644 --- a/src/test/ne_mem_test.cpp +++ b/src/test/unittests/ne_core_mem_test.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2019 Dongju Chae */ /** - * @file ne_mem_tests.cpp + * @file ne_core_mem_test.cpp * @date 30 Jun 2019 * @brief UnitTests to test functions in memory allocator for NPU Engine * @author Dongju Chae @@ -33,7 +33,7 @@ extern "C" * @brief register NPU model * @detail The memory size of model and I/O buffer will be provided as arguments */ -TEST (test_mem, register_model) +TEST (ne_core_mem_test, register_model) { mem *mem = GET_MEM (); hwmem *hwmem; @@ -60,7 +60,7 @@ TEST (test_mem, register_model) /** * @brief prepare input buffer */ -TEST (test_mem, prepare_input) +TEST (ne_core_mem_test, prepare_input) { mem *mem = GET_MEM (); buffer *buffer; @@ -101,7 +101,7 @@ TEST (test_mem, prepare_input) /** * @brief when output is ready (in a syncronized manner) */ -TEST (test_mem, output_ready) +TEST (ne_core_mem_test, output_ready) { mem *mem = GET_MEM (); buffer *buffer; @@ -249,7 +249,7 @@ output_thread (void* data) /** * @brief running in parallel with fork() */ -TEST (test_mem, running_parallel) +TEST (ne_core_mem_test, running_parallel) { mem *mem = GET_MEM (); uint64_t size_out, size_in = 1 * M; @@ -275,7 +275,7 @@ TEST (test_mem, running_parallel) /** * @brief test for memory compaction */ -TEST (test_mem, memory_compaction) +TEST (ne_core_mem_test, memory_compaction) { mem *mem = GET_MEM (); hwmem *hwmem[6]; @@ -393,7 +393,7 @@ get_buffer_wait_thread (void *data) /** * @brief test handling input priorities and synchronization for memory */ -TEST (test_mem, get_next_buffer_modes) +TEST (ne_core_mem_test, get_next_buffer_modes) { mem *mem = GET_MEM (); buffer *buffer1, *buffer2; diff --git a/src/test/npu_api_test.cpp b/src/test/unittests/ne_core_npu_test.cpp similarity index 96% rename from src/test/npu_api_test.cpp rename to src/test/unittests/ne_core_npu_test.cpp index 4c6d2fa..be76677 100644 --- a/src/test/npu_api_test.cpp +++ b/src/test/unittests/ne_core_npu_test.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2019 Parichay Kapoor */ /** - * @file npu_api_test.cpp + * @file ne_core_npu_test.cpp * @date 24 Jul 2019 * @brief Test npu driver api * @author Parichay Kapoor @@ -30,7 +30,7 @@ extern "C" /** * @brief base open and close a device */ -TEST (npu_api, dev_open_close) +TEST (ne_core_npu_test, dev_open_close) { int fd; int ret; @@ -80,7 +80,7 @@ TEST (npu_api, dev_open_close) /** * @brief set data in the device */ -TEST (npu_api, set_dev_data) +TEST (ne_core_npu_test, set_dev_data) { int fd = 1; int ret; @@ -139,7 +139,7 @@ TEST (npu_api, set_dev_data) /** * @brief check device statuses */ -TEST (npu_api, check_dev_status) +TEST (ne_core_npu_test, check_dev_status) { int fd = 1; int ret; diff --git a/src/test/ne_utils_test.cpp b/src/test/unittests/ne_core_utils_test.cpp similarity index 95% rename from src/test/ne_utils_test.cpp rename to src/test/unittests/ne_core_utils_test.cpp index fc89df1..b06e191 100644 --- a/src/test/ne_utils_test.cpp +++ b/src/test/unittests/ne_core_utils_test.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2019 Dongju Chae */ /** - * @file ne_utils_tests.cpp + * @file ne_core_utils_test.cpp * @date 30 Jun 2019 * @brief UnitTests to test functions in utility for NPU Engine * @author Dongju Chae @@ -33,7 +33,7 @@ typedef struct _test_elem { /** * @brief It tests the functionality of a linked list */ -TEST (test_ne_utils, linked_list) +TEST (ne_core_utils_test, linked_list) { test_elem *elem, *tmp; list test_list; @@ -76,7 +76,7 @@ TEST (test_ne_utils, linked_list) /** * @brief test functionality of a hash table */ -TEST (test_ne_utils, hash_table) +TEST (ne_core_utils_test, hash_table) { test_elem *elem, *tmp; hash_table test_ht; -- 2.7.4