Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation for Windows #217

Merged
merged 6 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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

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

find_package(OpenMP 4.5)
if (OpenMP_CXX_FOUND)
find_package(OpenMP)
salvacarrion marked this conversation as resolved.
Show resolved Hide resolved
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
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)
salvacarrion marked this conversation as resolved.
Show resolved Hide resolved
#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
salvacarrion marked this conversation as resolved.
Show resolved Hide resolved
for (long long 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 (long long 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 (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);
}

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 (long long 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 @@ -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
salvacarrion marked this conversation as resolved.
Show resolved Hide resolved
#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