From 4c504d17bbf520f1ff4a9c36ddf59e2493364f38 Mon Sep 17 00:00:00 2001 From: Michele Cancilla Date: Wed, 11 Nov 2020 18:20:46 +0100 Subject: [PATCH 1/5] Fix Windows errors related to "sys/time.h" --- include/eddl/profiling.h | 26 +++++++++++++++++++++----- src/hardware/cpu/cpu_core.cpp | 21 +-------------------- src/profiling.cpp | 23 +++++++++++++++++++++++ 3 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 src/profiling.cpp diff --git a/include/eddl/profiling.h b/include/eddl/profiling.h index 43ce4b9c5..8511d8c6a 100644 --- a/include/eddl/profiling.h +++ b/include/eddl/profiling.h @@ -1,14 +1,33 @@ -#ifndef _PROFILING +/* +* EDDL Library - European Distributed Deep Learning Library. +* Version: 0.7 +* copyright (c) 2020, Universidad Polit�cnica de Valencia (UPV), PRHLT Research Centre +* Date: April 2020 +* Author: PRHLT Research Centre, UPV, (rparedes@prhlt.upv.es), (jon@prhlt.upv.es) +* All rights reserved +*/ +#ifndef _PROFILING #define _PROFILING +#include "eddl/system_info.h" + +#ifdef EDDL_WINDOWS + +#include +#include +#include + +int gettimeofday(struct timeval* tp, struct timezone* tzp); + +#else #include +#endif #define PROFILING_HEADER(fn) \ struct timeval prof_t1; \ gettimeofday(&prof_t1, NULL); - #define PROFILING_ENABLE(fn) \ unsigned long long prof_##fn##_time; \ unsigned long long prof_##fn##_calls; @@ -44,8 +63,6 @@ 100.0 * prof_##fn##_time / acc, (float) prof_##fn##_time / (float) prof_##fn##_calls); #endif - - //CxHxW // //HxWxC @@ -53,4 +70,3 @@ //GxHxWxC (C=4) Reshape + Permute // //32xHxW -> Reshape -> 8x4xHxW -> Permute(0, 2, 3, 1) -> 8xHxWx4 // hay capas y funciones - diff --git a/src/hardware/cpu/cpu_core.cpp b/src/hardware/cpu/cpu_core.cpp index 17388b18f..b15e9a460 100644 --- a/src/hardware/cpu/cpu_core.cpp +++ b/src/hardware/cpu/cpu_core.cpp @@ -8,29 +8,10 @@ */ #include "eddl/hardware/cpu/cpu_tensor.h" +#include "eddl/profiling.h" #include #include -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) - - #include - #include - #include - - int gettimeofday(struct timeval* tp, struct timezone* tzp) - { - namespace sc = std::chrono; - sc::system_clock::duration d = sc::system_clock::now().time_since_epoch(); - sc::seconds s = sc::duration_cast(d); - tp->tv_sec = s.count(); - tp->tv_usec = sc::duration_cast(d - s).count(); - - return 0; - } -#else - #include -#endif - int num_instances[_NUM_CPU_FUNCS]; float mb_memory_needed; diff --git a/src/profiling.cpp b/src/profiling.cpp new file mode 100644 index 000000000..22e70a78c --- /dev/null +++ b/src/profiling.cpp @@ -0,0 +1,23 @@ +/* +* EDDL Library - European Distributed Deep Learning Library. +* Version: 0.7 +* copyright (c) 2020, Universidad Politécnica de Valencia (UPV), PRHLT Research Centre +* Date: April 2020 +* Author: PRHLT Research Centre, UPV, (rparedes@prhlt.upv.es), (jon@prhlt.upv.es) +* All rights reserved +*/ + +#include "eddl/profiling.h" + +#ifdef EDDL_WINDOWS +int gettimeofday(struct timeval* tp, struct timezone* tzp) +{ + namespace sc = std::chrono; + sc::system_clock::duration d = sc::system_clock::now().time_since_epoch(); + sc::seconds s = sc::duration_cast(d); + tp->tv_sec = s.count(); + tp->tv_usec = sc::duration_cast(d - s).count(); + + return 0; +} +#endif \ No newline at end of file From c681e94678b87d71def33b490b709ec3e5e4635d Mon Sep 17 00:00:00 2001 From: Michele Cancilla Date: Wed, 11 Nov 2020 18:23:21 +0100 Subject: [PATCH 2/5] Wrap OpenMP directives for Windows compatibility --- .github/workflows/build-cpu-windows.yml | 2 +- src/CMakeLists.txt | 6 +++--- src/hardware/cpu/cpu_comparison.cpp | 8 +++++++- src/hardware/cpu/nn/cpu_losses.cpp | 8 ++++---- src/net/net_api.cpp | 11 ++++++++--- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-cpu-windows.yml b/.github/workflows/build-cpu-windows.yml index a2688333b..8677e5c8c 100644 --- a/.github/workflows/build-cpu-windows.yml +++ b/.github/workflows/build-cpu-windows.yml @@ -21,7 +21,7 @@ jobs: run: | mkdir build cd build - cmake -G "Visual Studio 16 2019" -A x64 -T ClangCL -DBUILD_SUPERBUILD=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_TARGET=CPU .. + cmake -G "Visual Studio 16 2019" -A x64 -DBUILD_SUPERBUILD=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_TARGET=CPU .. shell: cmd - name: Build run: cmake --build build --config Release diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d874890b2..3b2fd40f4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -244,10 +244,10 @@ if(BUILD_OPENMP) # endif() # endif() - find_package(OpenMP 4.5) - if (OpenMP_CXX_FOUND) + find_package(OpenMP) + if(OpenMP_CXX_FOUND) target_link_libraries(${PROJECT_NAME} PUBLIC OpenMP::OpenMP_CXX) - if (${OpenMP_CXX_VERSION_MAJOR}) + if(${OpenMP_CXX_VERSION_MAJOR}) set(OpenMP_VERSION_MAJOR ${OpenMP_CXX_VERSION_MAJOR} CACHE INTERNAL "" FORCE) endif() target_compile_definitions(${PROJECT_NAME} PUBLIC OpenMP_VERSION_MAJOR=${OpenMP_VERSION_MAJOR}) diff --git a/src/hardware/cpu/cpu_comparison.cpp b/src/hardware/cpu/cpu_comparison.cpp index a119c56a4..4ffbfc64c 100644 --- a/src/hardware/cpu/cpu_comparison.cpp +++ b/src/hardware/cpu/cpu_comparison.cpp @@ -9,6 +9,7 @@ #include "eddl/hardware/cpu/cpu_tensor.h" +#include "eddl/system_info.h" #include // CPU: Logic functions: Truth value testing @@ -24,7 +25,9 @@ bool cpu_all(Tensor *A){ { res = false; } +#if defined(EDDL_LINUX) || defined(EDDL_UNIX) || defined(EDDL_APPLE) #pragma omp cancel for +#endif } } _profile(_CPU_ALL, 1); @@ -44,8 +47,9 @@ bool cpu_any(Tensor *A){ { res = true; } +#if defined(EDDL_LINUX) || defined(EDDL_UNIX) || defined(EDDL_APPLE) #pragma omp cancel for - +#endif } } _profile(_CPU_ANY, 1); @@ -155,7 +159,9 @@ bool cpu_allclose(Tensor *A, Tensor *B, float rtol, float atol, bool equal_nan){ if(first_idx < 0) { first_idx=i; } } +#if defined(EDDL_LINUX) || defined(EDDL_UNIX) || defined(EDDL_APPLE) #pragma omp cancel for +#endif } } _profile(_CPU_ALLCLOSE, 1); diff --git a/src/hardware/cpu/nn/cpu_losses.cpp b/src/hardware/cpu/nn/cpu_losses.cpp index 7b09baaf3..c4836d2d1 100644 --- a/src/hardware/cpu/nn/cpu_losses.cpp +++ b/src/hardware/cpu/nn/cpu_losses.cpp @@ -31,7 +31,7 @@ float cpu_categorical_cross_entropy(Tensor* y_true, Tensor* y_pred){ float eps = 10e-8; #pragma omp parallel for reduction(+:sum) - for (unsigned int bi = 0; bishape[0]; bi++) { // Batches + for (long long int bi = 0; bishape[0]; bi++) { // Batches unsigned int step_i = bi * y_true->stride[0]; // Compute cross-entropy @@ -51,7 +51,7 @@ void cpu_d_categorical_cross_entropy(Tensor* y_true, Tensor* y_pred, Tensor* del float eps = 10e-8; #pragma omp parallel for - for (unsigned int i = 0; isize; i++) { + for (long long int i = 0; isize; i++) { delta->ptr[i] = -y_true->ptr[i] * (1.0f/ (y_pred->ptr[i]+eps) ); } } @@ -61,7 +61,7 @@ float cpu_binary_cross_entropy(Tensor* y_true, Tensor* y_pred){ float eps = 10e-8; #pragma omp parallel for reduction(+:sum) - for (unsigned int i = 0; isize; i++) { + for (long long int i = 0; i < y_true->size; i++) { sum += y_true->ptr[i] * ::logf(y_pred->ptr[i]+eps) + (1.0-y_true->ptr[i]) * ::logf(1.0f-y_pred->ptr[i]+eps); } @@ -74,7 +74,7 @@ void cpu_d_binary_cross_entropy(Tensor* y_true, Tensor* y_pred, Tensor* delta){ float eps = 10e-8; #pragma omp parallel for - for (unsigned int i = 0; isize; i++) { + for (long long int i = 0; isize; i++) { delta->ptr[i] = -( y_true->ptr[i] * 1.0f/(y_pred->ptr[i]+eps) + (1.0-y_true->ptr[i]) * 1.0f/(1.0f-y_pred->ptr[i]+eps) * -1.0f ); } } diff --git a/src/net/net_api.cpp b/src/net/net_api.cpp index aaa49a7e7..7a9d53b19 100644 --- a/src/net/net_api.cpp +++ b/src/net/net_api.cpp @@ -15,10 +15,11 @@ #include #include #include +#include "eddl/layers/core/layer_core.h" #include "eddl/net/net.h" -#include "eddl/utils.h" #include "eddl/random.h" -#include "eddl/layers/core/layer_core.h" +#include "eddl/system_info.h" +#include "eddl/utils.h" #ifdef cFPGA @@ -151,9 +152,13 @@ void Net::run_snets(void *(*F)(void *t)) int rc; struct tdata td[100]; - int comp=snets.size(); + int comp = snets.size(); +#ifdef EDDL_WINDOWS + #pragma omp parallel for +#else #pragma omp taskloop num_tasks(comp) +#endif for (int i = 0; i < comp; i++) { // Thread params td[i].net = snets[i]; From 4538d7a073837e73050cd76a26bebfdaedd00d55 Mon Sep 17 00:00:00 2001 From: Michele Cancilla Date: Thu, 12 Nov 2020 11:48:34 +0100 Subject: [PATCH 3/5] Update Jenkinsfile with new Docker images --- Jenkinsfile | 92 +++++++++++++++++++++-------------------------------- 1 file changed, 36 insertions(+), 56 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a78be4789..a7407ac9a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,24 +7,24 @@ pipeline { agent { docker { label 'docker' - image 'stal12/ubuntu18-gcc5' + image 'pritt/base' } } stages { stage('Build') { steps { - timeout(15) { - echo 'Building..' - cmakeBuild buildDir: 'build', cmakeArgs: '-D BUILD_TESTS=ON', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [[withCmake: true]] - } + timeout(60) { + echo 'Building..' + cmakeBuild buildDir: 'build', cmakeArgs: '-DBUILD_TARGET=CPU -DBUILD_SUPERBUILD=ON -DBUILD_TESTS=ON', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [[withCmake: true]] + } } } stage('Test') { steps { - timeout(15) { - echo 'Testing..' - ctest arguments: '-C Debug -VV', installation: 'InSearchPath', workingDir: 'build' - } + timeout(15) { + echo 'Testing..' + ctest arguments: '-C Debug -VV', installation: 'InSearchPath', workingDir: 'build' + } } } stage('linux_end') { @@ -41,18 +41,18 @@ pipeline { stages { stage('Build') { steps { - timeout(15) { - echo 'Building..' - cmakeBuild buildDir: 'build', cmakeArgs: '-D BUILD_TESTS=ON', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [[withCmake: true]] - } + timeout(60) { + echo 'Building..' + cmakeBuild buildDir: 'build', cmakeArgs: '-DBUILD_TARGET=CPU -DBUILD_SHARED_LIBS=OFF -DBUILD_SUPERBUILD=ON -DBUILD_TESTS=ON', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [[withCmake: true]] + } } } stage('Test') { steps { - timeout(15) { - echo 'Testing..' - bat 'cd build && ctest -C Debug -VV' - } + timeout(15) { + echo 'Testing..' + bat 'cd build && ctest -C Debug -VV' + } } } stage('windows_end') { @@ -66,26 +66,26 @@ pipeline { agent { docker { label 'docker && gpu' - image 'stal12/cuda10-gcc5' + image 'pritt/base-cuda' args '--gpus 1' } } stages { stage('Build') { steps { - timeout(15) { - echo 'Building..' - cmakeBuild buildDir: 'build', cmakeArgs: '-D BUILD_TARGET=GPU -D BUILD_TESTS=ON', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [[withCmake: true]] - } - } + timeout(60) { + echo 'Building..' + cmakeBuild buildDir: 'build', cmakeArgs: '-DBUILD_TARGET=GPU -DBUILD_TESTS=ON -DBUILD_SUPERBUILD=ON', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [[withCmake: true]] + } + } } stage('Test') { steps { - timeout(15) { - echo 'Testing..' - ctest arguments: '-C Debug -VV', installation: 'InSearchPath', workingDir: 'build' - } - } + timeout(15) { + echo 'Testing..' + ctest arguments: '-C Debug -VV', installation: 'InSearchPath', workingDir: 'build' + } + } } stage('linux_gpu_end') { steps { @@ -101,18 +101,18 @@ pipeline { stages { stage('Build') { steps { - timeout(15) { - echo 'Building..' - cmakeBuild buildDir: 'build', cmakeArgs: '-D BUILD_TARGET=GPU -D BUILD_TESTS=ON', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [[withCmake: true]] - } + timeout(60) { + echo 'Building..' + cmakeBuild buildDir: 'build', cmakeArgs: '-DBUILD_TARGET=GPU -DBUILD_TESTS=ON -DBUILD_SUPERBUILD=ON', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [[withCmake: true]] + } } } stage('Test') { steps { - timeout(15) { - echo 'Testing..' - bat 'cd build && ctest -C Debug -VV' - } + timeout(15) { + echo 'Testing..' + bat 'cd build && ctest -C Debug -VV' + } } } stage('windows_gpu_end') { @@ -122,26 +122,6 @@ pipeline { } } } - stage('documentation') { - when { - branch 'master' - beforeAgent true - } - agent { - label 'windows && eddl_doxygen' - } - stages { - stage('Update documentation') { - steps { - timeout(15) { - bat 'cd docs\\doxygen && doxygen' - bat 'powershell -Command "(gc %EDDL_DOXYGEN_INPUT_COMMANDS%) -replace \'@local_dir\', \'docs\\build\\html\' | Out-File commands_out.txt"' - bat 'winscp /ini:nul /script:commands_out.txt' - } - } - } - } - } } } } From e69c6bb0cf1311cd9037958b3e5c685f043ebce4 Mon Sep 17 00:00:00 2001 From: Michele Cancilla Date: Thu, 12 Nov 2020 16:19:40 +0100 Subject: [PATCH 4/5] Replace long long int with int --- src/hardware/cpu/nn/cpu_losses.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hardware/cpu/nn/cpu_losses.cpp b/src/hardware/cpu/nn/cpu_losses.cpp index c4836d2d1..f24be6d5c 100644 --- a/src/hardware/cpu/nn/cpu_losses.cpp +++ b/src/hardware/cpu/nn/cpu_losses.cpp @@ -31,7 +31,7 @@ float cpu_categorical_cross_entropy(Tensor* y_true, Tensor* y_pred){ float eps = 10e-8; #pragma omp parallel for reduction(+:sum) - for (long long int bi = 0; bishape[0]; bi++) { // Batches + for (int bi = 0; bishape[0]; bi++) { // Batches unsigned int step_i = bi * y_true->stride[0]; // Compute cross-entropy @@ -51,7 +51,7 @@ void cpu_d_categorical_cross_entropy(Tensor* y_true, Tensor* y_pred, Tensor* del float eps = 10e-8; #pragma omp parallel for - for (long long int i = 0; isize; i++) { + for (int i = 0; isize; i++) { delta->ptr[i] = -y_true->ptr[i] * (1.0f/ (y_pred->ptr[i]+eps) ); } } @@ -61,7 +61,7 @@ float cpu_binary_cross_entropy(Tensor* y_true, Tensor* y_pred){ float eps = 10e-8; #pragma omp parallel for reduction(+:sum) - for (long long int i = 0; i < y_true->size; i++) { + for (int i = 0; i < y_true->size; i++) { sum += y_true->ptr[i] * ::logf(y_pred->ptr[i]+eps) + (1.0-y_true->ptr[i]) * ::logf(1.0f-y_pred->ptr[i]+eps); } @@ -74,7 +74,7 @@ void cpu_d_binary_cross_entropy(Tensor* y_true, Tensor* y_pred, Tensor* delta){ float eps = 10e-8; #pragma omp parallel for - for (long long int i = 0; isize; i++) { + for (int i = 0; isize; i++) { delta->ptr[i] = -( y_true->ptr[i] * 1.0f/(y_pred->ptr[i]+eps) + (1.0-y_true->ptr[i]) * 1.0f/(1.0f-y_pred->ptr[i]+eps) * -1.0f ); } } From 95156f58b9c349c87510afbc32ffd6b24ed30037 Mon Sep 17 00:00:00 2001 From: Michele Cancilla Date: Thu, 12 Nov 2020 16:21:43 +0100 Subject: [PATCH 5/5] Set OpenMP minimum version to 4.5 for *nix and Apple OSs --- src/CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3b2fd40f4..5d85a4f2a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -244,7 +244,12 @@ if(BUILD_OPENMP) # endif() # endif() - find_package(OpenMP) + if(WIN32) + find_package(OpenMP) + else() + # *nix and Apple + find_package(OpenMP 4.5) + endif() if(OpenMP_CXX_FOUND) target_link_libraries(${PROJECT_NAME} PUBLIC OpenMP::OpenMP_CXX) if(${OpenMP_CXX_VERSION_MAJOR}) @@ -437,7 +442,7 @@ endif() message(STATUS "-------------------------------------------" ) message(STATUS "OpenMP enabled: " ${USE_OPENMP} ) if(BUILD_OPENMP) -message(STATUS "OpenMP version: " ${OpenMP_VERSION_MAJOR} ) +message(STATUS "OpenMP version: " ${OpenMP_CXX_VERSION} ) message(STATUS "OpenMP gomp library: " ${OpenMP_gomp_LIBRARY} ) message(STATUS "OpenMP pthread library: " ${OpenMP_pthread_LIBRARY} ) endif()