Skip to content

Commit

Permalink
Merge pull request #217 from MicheleCancilla/develop
Browse files Browse the repository at this point in the history
Fix compilation for Windows
  • Loading branch information
salvacarrion authored Nov 12, 2020
2 parents b7190f2 + 95156f5 commit a0b40d4
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-cpu-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
92 changes: 36 additions & 56 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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') {
Expand All @@ -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 {
Expand All @@ -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') {
Expand All @@ -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'
}
}
}
}
}
}
}
}
Expand Down
26 changes: 21 additions & 5 deletions include/eddl/profiling.h
Original file line number Diff line number Diff line change
@@ -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, ([email protected]), ([email protected])
* All rights reserved
*/

#ifndef _PROFILING
#define _PROFILING

#include "eddl/system_info.h"

#ifdef EDDL_WINDOWS

#include <chrono>
#include <windows.h>
#include <winsock.h>

int gettimeofday(struct timeval* tp, struct timezone* tzp);

#else
#include <sys/time.h>
#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;
Expand Down Expand Up @@ -44,13 +63,10 @@
100.0 * prof_##fn##_time / acc, (float) prof_##fn##_time / (float) prof_##fn##_calls);
#endif



//CxHxW
//
//HxWxC
//
//GxHxWxC (C=4) Reshape + Permute
//
//32xHxW -> Reshape -> 8x4xHxW -> Permute(0, 2, 3, 1) -> 8xHxWx4 // hay capas y funciones

13 changes: 9 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,15 @@ if(BUILD_OPENMP)
# endif()
# endif()

find_package(OpenMP 4.5)
if (OpenMP_CXX_FOUND)
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})
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})
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion src/hardware/cpu/cpu_comparison.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


#include "eddl/hardware/cpu/cpu_tensor.h"
#include "eddl/system_info.h"
#include <limits>

// CPU: Logic functions: Truth value testing
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 1 addition & 20 deletions src/hardware/cpu/cpu_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,10 @@
*/

#include "eddl/hardware/cpu/cpu_tensor.h"
#include "eddl/profiling.h"
#include <algorithm>
#include <numeric>

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)

#include <chrono>
#include <windows.h>
#include <winsock.h>

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<sc::seconds>(d);
tp->tv_sec = s.count();
tp->tv_usec = sc::duration_cast<sc::microseconds>(d - s).count();

return 0;
}
#else
#include <sys/time.h>
#endif

int num_instances[_NUM_CPU_FUNCS];
float mb_memory_needed;

Expand Down
8 changes: 4 additions & 4 deletions src/hardware/cpu/nn/cpu_losses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; bi<y_true->shape[0]; bi++) { // Batches
for (int bi = 0; bi<y_true->shape[0]; bi++) { // Batches
unsigned int step_i = bi * y_true->stride[0];

// Compute cross-entropy
Expand All @@ -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; i<y_true->size; i++) {
for (int i = 0; i<y_true->size; i++) {
delta->ptr[i] = -y_true->ptr[i] * (1.0f/ (y_pred->ptr[i]+eps) );
}
}
Expand All @@ -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; 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);
}

Expand All @@ -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; i<y_true->size; i++) {
for (int i = 0; i<y_true->size; 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 );
}
}
11 changes: 8 additions & 3 deletions src/net/net_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
#include <string>
#include <chrono>
#include <stdexcept>
#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
Expand Down Expand Up @@ -150,9 +151,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];
Expand Down
23 changes: 23 additions & 0 deletions src/profiling.cpp
Original file line number Diff line number Diff line change
@@ -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, ([email protected]), ([email protected])
* 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<sc::seconds>(d);
tp->tv_sec = s.count();
tp->tv_usec = sc::duration_cast<sc::microseconds>(d - s).count();

return 0;
}
#endif

0 comments on commit a0b40d4

Please sign in to comment.