diff --git a/.gitmodules b/.gitmodules index cabe2a25cb..68d5adb55a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,7 @@ -[submodule "third_party/iniparser"] - path = third_party/iniparser +[submodule "subprojects/iniparser"] + path = subprojects/iniparser url = https://github.com/ndevilla/iniparser.git - [submodule "third_party/ruy"] path = third_party/ruy url = https://github.com/google/ruy + diff --git a/Applications/AlexNet/jni/meson.build b/Applications/AlexNet/jni/meson.build index cfc83e2c09..301c2b66d8 100644 --- a/Applications/AlexNet/jni/meson.build +++ b/Applications/AlexNet/jni/meson.build @@ -1,8 +1,15 @@ -build_root = meson.build_root() -res_path = meson.current_source_dir() / '..' / 'res' +fs = import('fs') +app_res_dir = fs.parent(meson.current_source_dir()) / 'res' +build_app_res_dir = nntr_app_resdir / 'AlexNet' -nntr_alex_resdir = nntr_app_resdir / 'AlexNet' -run_command('cp', '-lr', res_path, nntr_alex_resdir) +if host_machine.system() == 'windows' + app_res_dir_win = app_res_dir.replace('/', '\\') + build_app_res_dir_win = build_app_res_dir.replace('/', '\\') + run_command('cmd.exe', '/C', 'mkdir', build_app_res_dir_win) + run_command('cmd.exe', '/C', 'xcopy',app_res_dir_win, build_app_res_dir_win) +else + run_command('cp', '-lr', app_res_dir, build_app_res_dir) +endif alex_sources = [ 'main.cpp', diff --git a/Applications/Custom/LayerClient/jni/meson.build b/Applications/Custom/LayerClient/jni/meson.build index bbf6c738a8..0e6adf4021 100644 --- a/Applications/Custom/LayerClient/jni/meson.build +++ b/Applications/Custom/LayerClient/jni/meson.build @@ -1,4 +1,15 @@ -res_path = meson.current_source_dir() / '..' / 'res' +fs = import('fs') +app_res_dir = fs.parent(meson.current_source_dir()) / 'res' +build_app_res_dir = nntr_app_resdir / 'LayerClient' + +if host_machine.system() == 'windows' + app_res_dir_win = app_res_dir.replace('/', '\\') + build_app_res_dir_win = build_app_res_dir.replace('/', '\\') + run_command('cmd.exe', '/C', 'mkdir', build_app_res_dir_win) + run_command('cmd.exe', '/C', 'xcopy',app_res_dir_win, build_app_res_dir_win) +else + run_command('cp', '-lr', app_res_dir, build_app_res_dir) +endif layer_client_sources = [ 'main.cpp', @@ -6,8 +17,6 @@ layer_client_sources = [ layer_example_mae_src ] -run_command('cp', '-lr', res_path, nntr_app_resdir / 'LayerClient') - exe = executable('layer_client', layer_client_sources, include_directories: layer_example_inc, @@ -17,4 +26,4 @@ exe = executable('layer_client', ) test('app_layer_client_api', exe, args: 'model') -test('app_layer_client_ini', exe, args: res_path / 'custom_layer_client.ini') +test('app_layer_client_ini', exe, args: build_app_res_dir / 'custom_layer_client.ini') diff --git a/Applications/Layers/jni/meson.build b/Applications/Layers/jni/meson.build index 7e1b0c4102..00e3d853d6 100644 --- a/Applications/Layers/jni/meson.build +++ b/Applications/Layers/jni/meson.build @@ -1,8 +1,15 @@ -build_root = meson.build_root() -res_path = meson.current_source_dir() / '..' / 'res' +fs = import('fs') +app_res_dir = fs.parent(meson.current_source_dir()) / 'res' +build_app_res_dir = nntr_app_resdir / 'Layers' -nntr_Layers_resdir = nntr_app_resdir / 'Layers' -run_command('cp', '-lr', res_path, nntr_Layers_resdir) +if host_machine.system() == 'windows' + app_res_dir_win = app_res_dir.replace('/', '\\') + build_app_res_dir_win = build_app_res_dir.replace('/', '\\') + run_command('cmd.exe', '/C', 'mkdir', build_app_res_dir_win) + run_command('cmd.exe', '/C', 'xcopy',app_res_dir_win, build_app_res_dir_win) +else + run_command('cp', '-lr', app_res_dir, build_app_res_dir) +endif Layers_sources = [ 'main.cpp', diff --git a/Applications/LogisticRegression/jni/main.cpp b/Applications/LogisticRegression/jni/main.cpp index 6694c1c17a..be5f4a5b83 100644 --- a/Applications/LogisticRegression/jni/main.cpp +++ b/Applications/LogisticRegression/jni/main.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/Applications/LogisticRegression/jni/meson.build b/Applications/LogisticRegression/jni/meson.build index 8a6e54d9c3..9af13c36d6 100644 --- a/Applications/LogisticRegression/jni/meson.build +++ b/Applications/LogisticRegression/jni/meson.build @@ -1,5 +1,15 @@ -res_path = meson.current_source_dir() / '..' / 'res' -run_command('cp', '-lr', res_path, nntr_app_resdir / 'LogisticRegression') +fs = import('fs') +app_res_dir = fs.parent(meson.current_source_dir()) / 'res' +build_app_res_dir = nntr_app_resdir / 'LogisticRegression' + +if host_machine.system() == 'windows' + app_res_dir_win = app_res_dir.replace('/', '\\') + build_app_res_dir_win = build_app_res_dir.replace('/', '\\') + run_command('cmd.exe', '/C', 'mkdir', build_app_res_dir_win) + run_command('cmd.exe', '/C', 'xcopy',app_res_dir_win, build_app_res_dir_win) +else + run_command('cp', '-lr', app_res_dir, build_app_res_dir) +endif e = executable('nntrainer_logistic', 'main.cpp', @@ -9,6 +19,6 @@ e = executable('nntrainer_logistic', ) test('app_logistic', e, args: ['train', - nntr_app_resdir / 'LogisticRegression' / 'LogisticRegression.ini', - nntr_app_resdir / 'LogisticRegression' / 'dataset1.txt'] + build_app_res_dir / 'LogisticRegression.ini', + build_app_res_dir / 'dataset1.txt'] ) diff --git a/Applications/MNIST/jni/main.cpp b/Applications/MNIST/jni/main.cpp index 26b734413f..99736d65ac 100644 --- a/Applications/MNIST/jni/main.cpp +++ b/Applications/MNIST/jni/main.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/Applications/MNIST/jni/meson.build b/Applications/MNIST/jni/meson.build index 3c2d93ec4a..72d193eae4 100644 --- a/Applications/MNIST/jni/meson.build +++ b/Applications/MNIST/jni/meson.build @@ -1,7 +1,15 @@ -res_path = meson.current_source_dir() / '..' / 'res' -nntr_mnist_resdir = nntr_app_resdir / 'MNIST' +fs = import('fs') +app_res_dir = fs.parent(meson.current_source_dir()) / 'res' +build_app_res_dir = nntr_app_resdir / 'MNIST' -run_command('cp', '-lr', res_path, nntr_mnist_resdir) +if host_machine.system() == 'windows' + app_res_dir_win = app_res_dir.replace('/', '\\') + build_app_res_dir_win = build_app_res_dir.replace('/', '\\') + run_command('cmd.exe', '/C', 'mkdir', build_app_res_dir_win) + run_command('cmd.exe', '/C', 'xcopy',app_res_dir_win, build_app_res_dir_win) +else + run_command('cp', '-lr', app_res_dir, build_app_res_dir) +endif mnist_sources = [ 'main.cpp' @@ -23,8 +31,8 @@ test( 'app_mnist', e, args: [ - nntr_mnist_resdir / 'mnist.ini', - nntr_mnist_resdir / 'mnist_trainingSet.dat' + build_app_res_dir / 'mnist.ini', + build_app_res_dir / 'mnist_trainingSet.dat' ], timeout: 60 ) diff --git a/Applications/Multi_input/jni/multi_loader.cpp b/Applications/Multi_input/jni/multi_loader.cpp index 4cad437dd5..28102fd4ee 100644 --- a/Applications/Multi_input/jni/multi_loader.cpp +++ b/Applications/Multi_input/jni/multi_loader.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include namespace nntrainer::util { diff --git a/Applications/ProductRatings/jni/main.cpp b/Applications/ProductRatings/jni/main.cpp index 1d03afd585..ea746d68d6 100644 --- a/Applications/ProductRatings/jni/main.cpp +++ b/Applications/ProductRatings/jni/main.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include diff --git a/Applications/ProductRatings/jni/meson.build b/Applications/ProductRatings/jni/meson.build index 91fc573fe6..37abc3a6e1 100644 --- a/Applications/ProductRatings/jni/meson.build +++ b/Applications/ProductRatings/jni/meson.build @@ -1,5 +1,15 @@ -res_path = meson.current_source_dir() / '..' / 'res' -run_command('cp', '-lr', res_path, nntr_app_resdir / 'ProductRatings') +fs = import('fs') +app_res_dir = fs.parent(meson.current_source_dir()) / 'res' +build_app_res_dir = nntr_app_resdir / 'ProductRatings' + +if host_machine.system() == 'windows' + app_res_dir_win = app_res_dir.replace('/', '\\') + build_app_res_dir_win = build_app_res_dir.replace('/', '\\') + run_command('cmd.exe', '/C', 'mkdir', build_app_res_dir_win) + run_command('cmd.exe', '/C', 'xcopy',app_res_dir_win, build_app_res_dir_win) +else + run_command('cp', '-lr', app_res_dir, build_app_res_dir) +endif e = executable('nntrainer_product_ratings', 'main.cpp', @@ -10,6 +20,6 @@ e = executable('nntrainer_product_ratings', # test split example test('app_product_ratings', e, args: ['train', - nntr_app_resdir / 'ProductRatings' / 'product_ratings_model.ini', - nntr_app_resdir / 'ProductRatings' / 'sample_product_ratings.txt'] + build_app_res_dir / 'product_ratings_model.ini', + build_app_res_dir / 'sample_product_ratings.txt'] ) diff --git a/Applications/ReinforcementLearning/DeepQ/jni/meson.build b/Applications/ReinforcementLearning/DeepQ/jni/meson.build index 01caded345..6cefbb6ae6 100644 --- a/Applications/ReinforcementLearning/DeepQ/jni/meson.build +++ b/Applications/ReinforcementLearning/DeepQ/jni/meson.build @@ -6,6 +6,9 @@ run_command('cp', '-lr', res_path, nntr_deepq_resdir) env_dir='../../Environment' +jsoncpp_dep = dependency('jsoncpp') +libcurl_dep = dependency('libcurl') + deepq_sources = [ 'main.cpp', env_dir / 'CartPole/cartpole.cpp' diff --git a/Applications/SimpleFC/jni/main.cpp b/Applications/SimpleFC/jni/main.cpp index cddde98687..98505ad117 100644 --- a/Applications/SimpleFC/jni/main.cpp +++ b/Applications/SimpleFC/jni/main.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -20,7 +21,6 @@ #include #include #include -#include #ifdef PROFILE #include @@ -145,8 +145,8 @@ void createAndRun(unsigned int epochs, unsigned int batch_size, << std::endl; // to test asynch fsu, we do need save the model weight data in file - std::string filePath = "./simplefc_weight_fp16_fp16_100.bin"; - if (access(filePath.c_str(), F_OK) == 0) { + std::string filePath = "simplefc_weight_fp16_fp16_100.bin"; + if (std::filesystem::exists(filePath)) { model->load(filePath); } else { model->save(filePath, ml::train::ModelFormat::MODEL_FORMAT_BIN); diff --git a/Applications/YOLOv2/jni/det_dataloader.cpp b/Applications/YOLOv2/jni/det_dataloader.cpp index 8aebc2366f..41a4c7eaaa 100644 --- a/Applications/YOLOv2/jni/det_dataloader.cpp +++ b/Applications/YOLOv2/jni/det_dataloader.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include namespace nntrainer::util { diff --git a/Applications/YOLOv3/jni/det_dataloader.cpp b/Applications/YOLOv3/jni/det_dataloader.cpp index 74c7d53595..45b1ae2667 100644 --- a/Applications/YOLOv3/jni/det_dataloader.cpp +++ b/Applications/YOLOv3/jni/det_dataloader.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include namespace nntrainer::util { diff --git a/Applications/meson.build b/Applications/meson.build index 843347ceb5..bd4855cf7f 100644 --- a/Applications/meson.build +++ b/Applications/meson.build @@ -1,8 +1,13 @@ nntr_app_resdir = nntrainer_resdir / 'app' -run_command('mkdir', '-p', nntr_app_resdir) + +if host_machine.system() == 'windows' + nntr_app_resdir_win = nntr_app_resdir.replace('/', '\\') + run_command('cmd.exe', '/C', 'mkdir', nntr_app_resdir_win) +else + run_command('mkdir', '-p', nntr_app_resdir) +endif subdir('utils') -subdir('KNN/jni') subdir('LogisticRegression/jni') if enable_ccapi subdir('MNIST/jni') @@ -12,22 +17,28 @@ if enable_ccapi endif subdir('VGG/jni') subdir('Resnet/jni') -subdir('YOLOv2/jni') -subdir('YOLOv3/jni') -subdir('LLaMA/jni') subdir('Multi_input/jni') -subdir('ReinforcementLearning/DeepQ/jni') -subdir('TransferLearning/CIFAR_Classification/jni') + # if enable_capi # subdir('TransferLearning/Draw_Classification/jni') # endif -subdir('Custom') + subdir('ProductRatings/jni') subdir('AlexNet/jni') subdir('Layers/jni') if get_option('enable-tflite-backbone') subdir('SimpleShot') endif -subdir('PicoGPT/jni') subdir('SimpleFC/jni') + +if host_machine.system() != 'windows' + subdir('KNN/jni') + subdir('YOLOv2/jni') + subdir('YOLOv3/jni') + subdir('LLaMA/jni') + subdir('ReinforcementLearning/DeepQ/jni') + subdir('TransferLearning/CIFAR_Classification/jni') + subdir('Custom') + subdir('PicoGPT/jni') +endif diff --git a/Applications/utils/datagen/cifar/cifar_dataloader.cpp b/Applications/utils/datagen/cifar/cifar_dataloader.cpp index 7ec136ea24..932b9ec50d 100644 --- a/Applications/utils/datagen/cifar/cifar_dataloader.cpp +++ b/Applications/utils/datagen/cifar/cifar_dataloader.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include namespace nntrainer::util { diff --git a/Applications/utils/jni/bitmap_helpers.cpp b/Applications/utils/jni/bitmap_helpers.cpp index 0fc64acd50..655da60065 100644 --- a/Applications/utils/jni/bitmap_helpers.cpp +++ b/Applications/utils/jni/bitmap_helpers.cpp @@ -23,8 +23,6 @@ limitations under the License. #include #include -#include // NOLINT(build/include_order) - #include "bitmap_helpers.h" #define LOG(x) std::cerr diff --git a/benchmarks/benchmark_application/benchmark_resnet.cpp b/benchmarks/benchmark_application/benchmark_resnet.cpp index f9024beaff..46fabef4da 100644 --- a/benchmarks/benchmark_application/benchmark_resnet.cpp +++ b/benchmarks/benchmark_application/benchmark_resnet.cpp @@ -27,6 +27,7 @@ using ModelHandle = std::unique_ptr; using UserDataType = std::unique_ptr; uint64_t get_cpu_freq() { +#if not defined(_WIN32) unsigned int freq = 0; char cur_cpu_name[512]; int cpu = sched_getcpu(); @@ -41,6 +42,7 @@ uint64_t get_cpu_freq() { } fclose(f); } +#endif return 0; } diff --git a/benchmarks/benchmark_application/meson.build b/benchmarks/benchmark_application/meson.build index 1f3a386b65..c3a423fba5 100644 --- a/benchmarks/benchmark_application/meson.build +++ b/benchmarks/benchmark_application/meson.build @@ -7,7 +7,14 @@ resnet_dependencies = [nntrainer_dep, nntrainer_ccapi_dep, benchmark_dep, ] +benchmark_ling_args = '' + +if host_machine.system() == 'windows' + benchmark_ling_args = '-lshlwapi' +endif + executable('Benchmark_ResNet', sources, include_directories : [include_directories('.'), fake_datagen_include_dir], - dependencies : resnet_dependencies) + dependencies : resnet_dependencies, + link_args: benchmark_ling_args) diff --git a/benchmarks/fake_data_gen/fake_data_gen.cpp b/benchmarks/fake_data_gen/fake_data_gen.cpp index 5e941b731f..0eb4491030 100644 --- a/benchmarks/fake_data_gen/fake_data_gen.cpp +++ b/benchmarks/fake_data_gen/fake_data_gen.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include namespace nntrainer::util { diff --git a/meson.build b/meson.build index 0ec104d447..3f9c6367a5 100644 --- a/meson.build +++ b/meson.build @@ -8,14 +8,21 @@ project('nntrainer', 'c', 'cpp', 'c_std=gnu89', 'cpp_std=c++17', 'buildtype=release' - ], - subproject_dir: 'third_party' + ] ) # Set version info nntrainer_version = meson.project_version() nntrainer_version_split = nntrainer_version.split('.') +# CMake module +cmake = import('cmake') + +if host_machine.system() == 'windows' + windows_compile_args = ['/MT'] + add_project_arguments(windows_compile_args, language: ['c','cpp']) +endif + add_project_arguments('-DVERSION="' + nntrainer_version + '"', language: ['c', 'cpp']) add_project_arguments('-DVERSION_MAJOR=' + nntrainer_version_split[0], language: ['c', 'cpp']) add_project_arguments('-DVERSION_MINOR=' + nntrainer_version_split[1], language: ['c', 'cpp']) @@ -79,9 +86,13 @@ if get_option('enable-avx') if get_option('platform') != 'android' if target == 'x86_64' or target == 'x86' extra_defines += '-DUSE_AVX=1' - add_project_arguments(['-march=native'], language: ['c','cpp']) - add_project_arguments(['-mavx2'], language: ['c','cpp']) - message('-march=native added for AVX hardware acceleration.') + if host_machine.system() == 'windows' + add_project_arguments(['/arch:AVX2'], language: ['c','cpp']) + else + add_project_arguments(['-march=native'], language: ['c','cpp']) + add_project_arguments(['-mavx2'], language: ['c','cpp']) + message('-march=native added for AVX hardware acceleration.') + endif avx_enabled = true else warning('The target arch, ' + target + ', does not support AVX. enable-avx=true is ignored.') @@ -301,7 +312,21 @@ if get_option('enable-blas') blas_root = meson.build_root() / 'openblas' blas_dep = declare_dependency(include_directories: [ 'openblas/include' ]) else - blas_dep = dependency('openblas') + blas_dep = dependency('openblas', required : false) + + if not blas_dep.found() + blas_options = cmake.subproject_options() + if host_machine.system() == 'windows' + blas_options.append_compile_args('c', windows_compile_args) + blas_options.append_compile_args('cpp', windows_compile_args) + endif + blas_options.add_cmake_defines({'BUILD_TESTING': false}) + blas_options.add_cmake_defines({'BUILD_BENCHMARKS': false}) + blas_options.add_cmake_defines({'BUILD_SHARED_LIBS': false}) + blas_options.add_cmake_defines({'BUILD_WITHOUT_LAPACK': true}) + blas_subproject = cmake.subproject('openblas', options: blas_options, required: true) + blas_dep = blas_subproject.dependency('openblas_static') + endif endif if blas_dep.found() @@ -345,10 +370,38 @@ if get_option('enable-logging') extra_defines += '-D__LOGGING__=1' endif +if get_option('enable-benchmarks') + benchmark_dep = dependency('benchmark', static : true, main : false, required : false) + if not benchmark_dep.found() + benchmark_options = cmake.subproject_options() + if host_machine.system() == 'windows' + benchmark_options.append_compile_args('c', windows_compile_args) + benchmark_options.append_compile_args('cpp', windows_compile_args) + endif + benchmark_options.add_cmake_defines({'BENCHMARK_ENABLE_TESTING': false}) + benchmark_subproject = cmake.subproject('benchmark', options: benchmark_options, required: true) + benchmark_dep = benchmark_subproject.dependency('benchmark') + message('benchmar targets') + message(benchmark_subproject.target_list()) + endif +endif + gmock_dep = dependency('gmock', static: true, main: false, required: false) gtest_dep = dependency('gtest', static: true, main: false, required: false) gtest_main_dep = dependency('gtest', static: true, main: true, required: false) -benchmark_dep = dependency('benchmark', static : true, main : false, required : false) + +if not gmock_dep.found() or not gtest_dep.found() or not gtest_main_dep.found() + googletest_options = cmake.subproject_options() + if host_machine.system() == 'windows' + googletest_options.append_compile_args('c', windows_compile_args) + googletest_options.append_compile_args('cpp', windows_compile_args) + endif + googletest_options.add_cmake_defines({'BUILD_SHARED_LIBS': false}) + googletest_subproject = cmake.subproject('googletest', options: googletest_options, required: true) + gmock_dep = googletest_subproject.dependency('gmock') + gtest_dep = googletest_subproject.dependency('gtest') + gtest_main_dep = googletest_subproject.dependency('gtest_main') +endif if get_option('enable-test') # and get_option('platform') != 'android' extra_defines += '-DENABLE_TEST=1' @@ -370,17 +423,17 @@ endif thread_dep = dependency('threads') # pthread for tensorflow-lite if get_option('platform') == 'android' - iniparser_root = meson.source_root() / 'third_party' / 'iniparser' + iniparser_root = meson.source_root() / 'subprojects' / 'iniparser' iniparser_dep = declare_dependency() else iniparser_dep = dependency('iniparser', required : false, version : '>=3.2') # iniparser if not iniparser_dep.found() - # CMake module - cmake = import('cmake') - - # iniparser iniparser_options = cmake.subproject_options() + if host_machine.system() == 'windows' + iniparser_options.append_compile_args('c', windows_compile_args) + iniparser_options.append_compile_args('cpp', windows_compile_args) + endif iniparser_options.add_cmake_defines({'BUILD_DOCS': false}) iniparser_options.add_cmake_defines({'BUILD_EXAMPLES': false}) iniparser_options.add_cmake_defines({'BUILD_TESTING': false}) @@ -494,11 +547,10 @@ if get_option('enable-app') if get_option('platform') == 'android' warning('android app is not supported for now, building app skipped') else - # this is needed for reinforcement application. We can move this to reinforecement app dependency - jsoncpp_dep = dependency('jsoncpp') # jsoncpp - libcurl_dep = dependency('libcurl') - if not tflite_dep.found() - error('Tensorflow-Lite dependency not found') + if host_machine.system() != 'windows' + if not tflite_dep.found() + error('Tensorflow-Lite dependency not found') + endif endif subdir('Applications') endif diff --git a/nntrainer/app_context.cpp b/nntrainer/app_context.cpp index d1109ba52c..a53d6b6b9a 100644 --- a/nntrainer/app_context.cpp +++ b/nntrainer/app_context.cpp @@ -207,7 +207,7 @@ std::vector getPluginPaths() { const std::string getFullPath(const std::string &path, const std::string &base) { /// if path is absolute, return path - if (path[0] == '/') { + if (std::filesystem::path(path).is_absolute()) { return path; } @@ -215,7 +215,9 @@ const std::string getFullPath(const std::string &path, return path == std::string() ? "." : path; } - return path == std::string() ? base : base + "/" + path; + return path == std::string() + ? base + : std::filesystem::path(base).append(path).string(); } } // namespace diff --git a/nntrainer/meson.build b/nntrainer/meson.build index b09cb96807..823b5c8f01 100644 --- a/nntrainer/meson.build +++ b/nntrainer/meson.build @@ -19,22 +19,18 @@ nntrainer_headers = [ meson.current_source_dir() / 'app_context.h', ] -# Dependencies -if host_machine.system() == 'windows' - nntrainer_base_deps=[ - iniparser_dep, - thread_dep, - openmp_dep - ] -else - nntrainer_base_deps=[ - blas_dep, - iniparser_dep, - ml_api_common_dep, +nntrainer_base_deps=[ + blas_dep, + iniparser_dep, + ml_api_common_dep, + thread_dep, + openmp_dep +] + +if host_machine.system() != 'windows' + nntrainer_base_deps += [ libm_dep, - libdl_dep, - thread_dep, - openmp_dep + libdl_dep ] endif diff --git a/nntrainer/models/model_loader.cpp b/nntrainer/models/model_loader.cpp index febb01c9c6..92901b2bc6 100644 --- a/nntrainer/models/model_loader.cpp +++ b/nntrainer/models/model_loader.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -481,14 +482,8 @@ int ModelLoader::loadFromConfig(std::string config, NeuralNetwork &model) { std::string config_realpath(config_realpath_char); free(config_realpath_char); - auto pos = config_realpath.find_last_of("/"); - if (pos == std::string::npos) { - ml_loge("resolved model path does not contain any path separator. %s", - config_realpath.c_str()); - return ML_ERROR_UNKNOWN; - } - - auto base_path = config_realpath.substr(0, pos); + auto base_path = + std::filesystem::path(config_realpath).parent_path().string(); model_file_context->setWorkingDirectory(base_path); ml_logd("for the current model working directory is set to %s", base_path.c_str()); diff --git a/nntrainer/tensor/blas_avx.cpp b/nntrainer/tensor/blas_avx.cpp index 7042dc6c70..dba1220c02 100644 --- a/nntrainer/tensor/blas_avx.cpp +++ b/nntrainer/tensor/blas_avx.cpp @@ -278,11 +278,16 @@ void custom_scopy(const unsigned int N, const float *X, const int incX, float *Y, const int incY) { unsigned int N8 = (N >> 3) << 3; for (unsigned int i = 0; i < N8; i += 8) { +#if defined(_WIN32) + __m256 temp = _mm256_loadu_ps(&X[i]); + _mm256_storeu_ps(&Y[i], temp); +#else __asm__ __volatile__("vmovups (%1), %%ymm0\n\t" "vmovups %%ymm0, (%0)\n\t" : : "r"(&Y[i]), "r"(&X[i]) : "ymm0", "memory"); +#endif } for (unsigned int i = N8; i < N; ++i) { Y[i] = X[i]; diff --git a/subprojects/benchmark.wrap b/subprojects/benchmark.wrap new file mode 100644 index 0000000000..a6286d550e --- /dev/null +++ b/subprojects/benchmark.wrap @@ -0,0 +1,4 @@ +[wrap-git] +url = https://github.com/google/benchmark.git +directory=benchmark +revision = v1.9.1 diff --git a/subprojects/googletest.wrap b/subprojects/googletest.wrap new file mode 100644 index 0000000000..537da863e1 --- /dev/null +++ b/subprojects/googletest.wrap @@ -0,0 +1,4 @@ +[wrap-git] +url = https://github.com/google/googletest.git +directory=googletest +revision = v1.15.2 diff --git a/third_party/iniparser b/subprojects/iniparser similarity index 100% rename from third_party/iniparser rename to subprojects/iniparser diff --git a/third_party/iniparser.wrap b/subprojects/iniparser.wrap similarity index 100% rename from third_party/iniparser.wrap rename to subprojects/iniparser.wrap diff --git a/subprojects/openblas.wrap b/subprojects/openblas.wrap new file mode 100644 index 0000000000..c9fb6c8523 --- /dev/null +++ b/subprojects/openblas.wrap @@ -0,0 +1,4 @@ +[wrap-git] +url = https://github.com/OpenMathLib/OpenBLAS.git +directory=OpenBLAS +revision = v0.3.29 diff --git a/test/meson.build b/test/meson.build index b3d99e92cf..038a2f1c3d 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,5 +1,15 @@ nntrainer_test_resdir = nntrainer_resdir / 'test' -run_command('mkdir', '-p', nntrainer_test_resdir) + +if host_machine.system() == 'windows' + nntrainer_test_resdir_win = nntrainer_test_resdir.replace('/', '\\') + nntrainer_test_resdir_models_win = (nntrainer_test_resdir / 'test_models/').replace('/', '\\') + test_models_dir_win = (meson.current_source_dir() / 'test_models/').replace('/', '\\') + run_command('cmd.exe', '/C', 'mkdir', nntrainer_test_resdir_win) + run_command('cmd.exe', '/C', 'mkdir', nntrainer_test_resdir_models_win) + run_command('cmd.exe', '/C', 'xcopy',test_models_dir_win, nntrainer_test_resdir_models_win, '/i', '/s', '/y') +else + run_command('mkdir', '-p', nntrainer_test_resdir) +endif nntrainer_test_inc = include_directories('./include') diff --git a/test/nntrainer_test_util.cpp b/test/nntrainer_test_util.cpp index 7ff307558d..791f9dd7d3 100644 --- a/test/nntrainer_test_util.cpp +++ b/test/nntrainer_test_util.cpp @@ -24,10 +24,12 @@ #include "nntrainer_test_util.h" #include #include +#include #include #include #include #include +#include #include #include #include @@ -217,22 +219,21 @@ const std::string getResPath(const std::string &filename, const std::initializer_list fallback_base) { static const char *prefix = std::getenv("NNTRAINER_RESOURCE_PATH"); - static const char *fallback_prefix = "./res"; + auto fallback_prefix = std::filesystem::current_path().append("res").string(); - std::stringstream ss; if (prefix != nullptr) { - ss << prefix << '/' << filename; - return ss.str(); + return std::filesystem::path(prefix).append(filename).string(); } - ss << fallback_prefix; + auto res_path = std::filesystem::path(fallback_prefix); + for (auto &folder : fallback_base) { - ss << '/' << folder; + res_path.append(folder); } - ss << '/' << filename; + res_path.append(filename); - return ss.str(); + return res_path.string(); } nntrainer::GraphRepresentation diff --git a/test/unittest/compiler/meson.build b/test/unittest/compiler/meson.build index cf9a864577..221ebc0f82 100644 --- a/test/unittest/compiler/meson.build +++ b/test/unittest/compiler/meson.build @@ -4,10 +4,13 @@ test_target = [ 'compiler_test_util.cpp', 'unittest_compiler.cpp', 'unittest_interpreter.cpp', - 'unittest_tflite_export.cpp', 'unittest_realizer.cpp', ] +if get_option('enable-tflite-interpreter') + test_target += ['unittest_tflite_export.cpp'] +endif + exe = executable( test_name, test_target, diff --git a/test/unittest/datasets/unittest_iteration_queue.cpp b/test/unittest/datasets/unittest_iteration_queue.cpp index 808472f19b..dc4e47e1f0 100644 --- a/test/unittest/datasets/unittest_iteration_queue.cpp +++ b/test/unittest/datasets/unittest_iteration_queue.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/test/unittest/integration_tests/integration_test_loss.cpp b/test/unittest/integration_tests/integration_test_loss.cpp index ac5571f75d..e3d41f5108 100644 --- a/test/unittest/integration_tests/integration_test_loss.cpp +++ b/test/unittest/integration_tests/integration_test_loss.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include diff --git a/test/unittest/layers/meson.build b/test/unittest/layers/meson.build index 54d7d782fa..5746824ca5 100644 --- a/test/unittest/layers/meson.build +++ b/test/unittest/layers/meson.build @@ -2,10 +2,16 @@ layer_common_test_inc = [ include_directories('./', '../../include') ] layer_common_test_standalone_files = files('layers_standalone_common_tests.cpp') layer_common_test_dependent_files = files('layers_dependent_common_tests.cpp') +if host_machine.system() == 'windows' + cpp_args_str = '' +else + cpp_args_str = '-Wno-maybe-uninitialized' +endif + nntrainer_layer_common_standalone_tests_lib = shared_library( 'nntrainer_layer_common_standalone_tests', 'layers_standalone_common_tests.cpp', - cpp_args : '-Wno-maybe-uninitialized', + cpp_args : cpp_args_str, dependencies: [nntrainer_dep, gtest_dep], # nntrainer_devel_dep include_directories: layer_common_test_inc ) @@ -18,7 +24,7 @@ nntrainer_layer_common_standalone_tests_dep = declare_dependency( nntrainer_layer_common_dependent_tests_lib = shared_library( 'nntrainer_layer_common_dependent_tests', 'layers_dependent_common_tests.cpp', - cpp_args : '-Wno-maybe-uninitialized', + cpp_args : cpp_args_str, dependencies: [nntrainer_dep, gtest_dep], # nntrainer_devel_dep include_directories: layer_common_test_inc ) @@ -94,7 +100,7 @@ exe = executable( dependencies: [ nntrainer_test_main_deps, ], - cpp_args : '-Wno-maybe-uninitialized', + cpp_args : cpp_args_str, install: get_option('enable-test'), install_dir: application_install_dir ) diff --git a/test/unittest/memory/meson.build b/test/unittest/memory/meson.build index aee5cbbd1c..a7d9e127b9 100644 --- a/test/unittest/memory/meson.build +++ b/test/unittest/memory/meson.build @@ -11,13 +11,19 @@ test_target = [ 'unittest_cache_pool.cpp' ] +if host_machine.system() == 'windows' + cpp_args_str = '' +else + cpp_args_str = '-Wno-maybe-uninitialized' +endif + # memory unittests exe = executable( 'unittest_memory', test_target, dependencies: [ nntrainer_test_main_deps ], - cpp_args : '-Wno-maybe-uninitialized', + cpp_args : cpp_args_str, install: get_option('enable-test'), install_dir: application_install_dir ) diff --git a/test/unittest/memory/unittest_memory_planner.cpp b/test/unittest/memory/unittest_memory_planner.cpp index 885ac1e8e0..4ac6208ef4 100644 --- a/test/unittest/memory/unittest_memory_planner.cpp +++ b/test/unittest/memory/unittest_memory_planner.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include constexpr unsigned int MEM_BYTES = 128; diff --git a/test/unittest/meson.build b/test/unittest/meson.build index 958a10f01d..2180dbedab 100644 --- a/test/unittest/meson.build +++ b/test/unittest/meson.build @@ -27,11 +27,28 @@ dest_path = nntrainer_test_resdir foreach target: unzip_target _src_path = src_path / target[0] - run_command('mkdir', '-p', dest_path / target[1]) - run_command(['tar', 'xzf', _src_path, '-C', dest_path / target[1]]) + _dest_path = dest_path / target[1] + + if host_machine.system() == 'windows' + _src_path_win = _src_path.replace('/', '\\') + _dest_path_win = _dest_path.replace('/', '\\') + run_command('cmd.exe', '/C', 'mkdir', _dest_path_win) + run_command('cmd.exe', '/C', 'tar', 'xzf', _src_path_win, '-C', _dest_path_win) + else + run_command('mkdir', '-p', _dest_path) + run_command(['tar', 'xzf', _src_path, '-C', _dest_path]) + endif endforeach -run_command(['cp', '-l', src_path / 'label.dat', dest_path / 'label.dat']) +src_path_label = src_path / 'label.dat' +dest_path_label = dest_path / 'label.dat' +if host_machine.system() == 'windows' + src_path_label_win = src_path_label.replace('/', '\\') + dest_path_label_win = dest_path_label.replace('/', '\\') + run_command('cmd.exe', '/C', 'copy', src_path_label_win, dest_path_label_win) +else + run_command(['cp', '-l', src_path_label, dest_path_label]) +endif test_target = [ ['unittest_nntrainer_activations', []], diff --git a/test/unittest/unittest_base_properties.cpp b/test/unittest/unittest_base_properties.cpp index e25c97386a..2b1b5cf4ab 100644 --- a/test/unittest/unittest_base_properties.cpp +++ b/test/unittest/unittest_base_properties.cpp @@ -293,7 +293,7 @@ TEST(BasicProperty, valid_p) { { /**< from_string -> get / to_string, uint vector prop */ std::vector bananas; - EXPECT_EQ(nntrainer::getPropKey(bananas), "num_banana"); + EXPECT_STREQ(nntrainer::getPropKey(bananas), "num_banana"); nntrainer::from_string("1, 2,3, 4, 5", bananas); auto expected = std::vector({1, 2, 3, 4, 5}); EXPECT_EQ(bananas, expected); @@ -302,7 +302,7 @@ TEST(BasicProperty, valid_p) { { /**< from_string -> get / to_string, uint array prop */ std::array bananas; - EXPECT_EQ(nntrainer::getPropKey(bananas), "num_banana"); + EXPECT_STREQ(nntrainer::getPropKey(bananas), "num_banana"); nntrainer::from_string("1, 2,3, 4", bananas); auto expected = std::array({1, 2, 3, 4}); EXPECT_EQ(bananas, expected); diff --git a/test/unittest/unittest_nntrainer_appcontext.cpp b/test/unittest/unittest_nntrainer_appcontext.cpp index c7249a4dc7..12d35bcf46 100644 --- a/test/unittest/unittest_nntrainer_appcontext.cpp +++ b/test/unittest/unittest_nntrainer_appcontext.cpp @@ -14,10 +14,10 @@ #include +#include #include #include #include -#include #include #include @@ -34,10 +34,11 @@ class nntrainerAppContextDirectory : public ::testing::Test { protected: void SetUp() override { - int status = mkdir("testdir", 0777); - ASSERT_EQ(status, 0); + auto status = std::filesystem::create_directory("testdir"); + ASSERT_EQ(status, true); - std::ofstream file("testdir/testfile.txt"); + std::ofstream file( + std::filesystem::path("testdir").append("testfile.txt").string()); ASSERT_EQ(file.fail(), false); file << "testdata"; @@ -52,7 +53,8 @@ class nntrainerAppContextDirectory : public ::testing::Test { } void TearDown() override { - int status = remove("testdir/testfile.txt"); + int status = remove( + std::filesystem::path("testdir").append("testfile.txt").string().c_str()); ASSERT_EQ(status, 0); status = rmdir("testdir"); @@ -71,7 +73,9 @@ TEST_F(nntrainerAppContextDirectory, readFromGetPath_p) { ac.setWorkingDirectory("testdir"); path = ac.getWorkingPath("testfile.txt"); - EXPECT_EQ(path, current_directory + "/testdir/testfile.txt"); + EXPECT_EQ(path, std::filesystem::path(current_directory) + .append("testdir") + .append("testfile.txt")); std::ifstream file(path); std::string s; @@ -80,11 +84,12 @@ TEST_F(nntrainerAppContextDirectory, readFromGetPath_p) { file.close(); - path = ac.getWorkingPath("/absolute/path"); - EXPECT_EQ(path, "/absolute/path"); + const auto current_path_absolute = std::filesystem::current_path().string(); + path = ac.getWorkingPath(current_path_absolute); + EXPECT_EQ(path, current_path_absolute); path = ac.getWorkingPath(""); - EXPECT_EQ(path, current_directory + "/testdir"); + EXPECT_EQ(path, std::filesystem::path(current_directory).append("testdir")); } TEST_F(nntrainerAppContextDirectory, notExisitingSetDirectory_n) { diff --git a/test/unittest/unittest_nntrainer_models.cpp b/test/unittest/unittest_nntrainer_models.cpp index 55306a8263..e395bd0a30 100644 --- a/test/unittest/unittest_nntrainer_models.cpp +++ b/test/unittest/unittest_nntrainer_models.cpp @@ -1002,9 +1002,6 @@ GTEST_PARAMETER_TEST( mkModelIniTc(mnist_conv_cross_one_input, "1:1:1:10", 10, ModelTestOption::ALL), /**< augmentation layer */ - #if defined(ENABLE_DATA_AUGMENTATION_OPENCV) - mkModelIniTc(preprocess_translate, "3:1:1:10", 10, ModelTestOption::NO_THROW_RUN), - #endif mkModelIniTc(preprocess_flip_validate, "3:1:1:10", 10, ModelTestOption::NO_THROW_RUN), mkModelIniTc(preprocess_l2norm_validate, "3:1:1:10", 10, ModelTestOption::NO_THROW_RUN), @@ -1052,6 +1049,15 @@ GTEST_PARAMETER_TEST( }); // clang-format on +#if defined(ENABLE_DATA_AUGMENTATION_OPENCV) +GTEST_PARAMETER_TEST( + nntrainerModelAutoTestsAugmentationCV, nntrainerModelTest, + ::testing::ValuesIn({mkModelIniTc(preprocess_translate, "3:1:1:10", 10, + ModelTestOption::NO_THROW_RUN)}), + [](const testing::TestParamInfo &info) + -> const auto & { return std::get<1>(info.param); }); +#endif + /** * @brief Read or save the model before initialize */ diff --git a/test/unittest/unittest_nntrainer_tensor.cpp b/test/unittest/unittest_nntrainer_tensor.cpp index 0e72837f13..0c18bc3fc6 100644 --- a/test/unittest/unittest_nntrainer_tensor.cpp +++ b/test/unittest/unittest_nntrainer_tensor.cpp @@ -3795,7 +3795,7 @@ TEST(nntrainer_Tensor, save_read_01_p) { target.save(save_file); save_file.close(); - std::ifstream read_file("save.bin"); + std::ifstream read_file("save.bin", std::ios::in | std::ios::binary); readed.read(read_file); read_file.close(); @@ -3823,7 +3823,7 @@ TEST(nntrainer_Tensor, save_read_02_p) { target.save(save_file); save_file.close(); - std::ifstream read_file("save_qint16.bin"); + std::ifstream read_file("save_qint16.bin", std::ios::in | std::ios::binary); readed.read(read_file); read_file.close(); @@ -3854,7 +3854,7 @@ TEST(nntrainer_Tensor, save_read_03_p) { target.save(save_file); save_file.close(); - std::ifstream read_file("save_quint16.bin"); + std::ifstream read_file("save_quint16.bin", std::ios::in | std::ios::binary); readed.read(read_file); read_file.close(); @@ -3880,7 +3880,7 @@ TEST(nntrainer_Tensor, save_read_01_n) { target.save(save_file); save_file.close(); - std::ifstream read_file("save.bin"); + std::ifstream read_file("save.bin", std::ios::in | std::ios::binary); readed.read(read_file); read_file.close(); diff --git a/windows-native.ini b/windows-native.ini index dced674ef9..8912688026 100644 --- a/windows-native.ini +++ b/windows-native.ini @@ -1,14 +1,8 @@ [project options] - -enable-blas=false enable-tflite-backbone=false -enable-memory-swap=false enable-nnstreamer-backbone=false enable-tflite-interpreter=false -enable-app=false -enable-test=false install-app=false -enable-avx=false enable-mmap=false [built-in options]