Skip to content

Commit

Permalink
Merge pull request #341 from deephealthproject/develop
Browse files Browse the repository at this point in the history
Add RiscV flags
  • Loading branch information
salvacarrion authored Oct 24, 2022
2 parents 5ad2a2a + 6964bca commit d708158
Show file tree
Hide file tree
Showing 24 changed files with 117 additions and 55 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cmake_minimum_required(VERSION 3.9.2)

# User options
option(BUILD_SUPERBUILD "Compile using the superbuild system" OFF)
option(BUILD_RISCV "Compile for a RISCV cpu" OFF)
option(BUILD_PROTOBUF "Compile using Protobuf" ON)
option(BUILD_OPENMP "Compile using OpenMP" ON)
option(BUILD_HPC "Compile using aggressive flags for performance" ON)
Expand Down Expand Up @@ -194,4 +195,4 @@ endif()
if(BUILD_TESTS AND BUILD_HPC)
message(WARNING "[WARNING] Some logic functions are not compatible with the 'BUILD_HPC' flag.
If you're unit testing, or using one of these logic functions: isfinite(), isinf(), isnan(), isposinf(), isneginf(); then we recommend you to disable the HPC flag: '-D BUILD_HPC=OFF' to obtain the expected results.")
endif()
endif()
12 changes: 6 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ pipeline {
agent {
docker {
label 'docker'
image 'pritt/base'
image 'aimagelab/base'
}
}
stages {
stage('Build') {
steps {
timeout(60) {
echo 'Building..'
cmakeBuild buildDir: 'build', buildType: 'Release', cmakeArgs: '-DBUILD_TARGET=CPU -DBUILD_SUPERBUILD=ON -DBUILD_TESTS=ON', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [
cmakeBuild buildDir: 'build', buildType: 'Release', cmakeArgs: '-DBUILD_TARGET=CPU -DBUILD_SUPERBUILD=ON -DBUILD_TESTS=ON -DBUILD_HPC=OFF -DBUILD_DIST=OFF -DBUILD_RUNTIME=OFF', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [
[args: '--parallel 4', withCmake: true]
]
}
Expand Down Expand Up @@ -45,7 +45,7 @@ pipeline {
steps {
timeout(60) {
echo 'Building..'
cmakeBuild buildDir: 'build', buildType: 'Release', cmakeArgs: '-DBUILD_TARGET=CPU -DBUILD_SHARED_LIBS=OFF -DBUILD_SUPERBUILD=ON -DBUILD_TESTS=ON', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [
cmakeBuild buildDir: 'build', buildType: 'Release', cmakeArgs: '-DBUILD_TARGET=CPU -DBUILD_SHARED_LIBS=OFF -DBUILD_SUPERBUILD=ON -DBUILD_TESTS=ON -DBUILD_HPC=OFF -DBUILD_DIST=OFF -DBUILD_RUNTIME=OFF', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [
[args: '--config Release --parallel 4', withCmake: true]
]
}
Expand All @@ -70,7 +70,7 @@ pipeline {
agent {
docker {
label 'docker && gpu'
image 'pritt/base-cuda'
image 'aimagelab/base-cuda'
args '--gpus 1'
}
}
Expand All @@ -79,7 +79,7 @@ pipeline {
steps {
timeout(60) {
echo 'Building..'
cmakeBuild buildDir: 'build', buildType: 'Release', cmakeArgs: '-DBUILD_TARGET=GPU -DBUILD_TESTS=ON -DBUILD_SUPERBUILD=ON', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [
cmakeBuild buildDir: 'build', buildType: 'Release', cmakeArgs: '-DBUILD_TARGET=GPU -DBUILD_TESTS=ON -DBUILD_SUPERBUILD=ON -DBUILD_HPC=OFF -DBUILD_DIST=OFF -DBUILD_RUNTIME=OFF', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [
[args: '--parallel 4', withCmake: true]
]
}
Expand Down Expand Up @@ -109,7 +109,7 @@ pipeline {
steps {
timeout(60) {
echo 'Building..'
cmakeBuild buildDir: 'build', buildType: 'Release', cmakeArgs: '-DBUILD_TARGET=GPU -DBUILD_TESTS=ON -DBUILD_SUPERBUILD=ON', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [
cmakeBuild buildDir: 'build', buildType: 'Release', cmakeArgs: '-DBUILD_TARGET=GPU -DBUILD_TESTS=ON -DBUILD_SUPERBUILD=ON -DBUILD_HPC=OFF -DBUILD_DIST=OFF -DBUILD_RUNTIME=OFF', installation: 'InSearchPath', sourceDir: '.', cleanBuild: true, steps: [
[args: '--config Release --parallel 4', withCmake: true]
]
}
Expand Down
2 changes: 1 addition & 1 deletion cmake/googletest.CMakeLists.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include(ExternalProject)
ExternalProject_Add(googletest
PREFIX googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG "release-1.10.0"
GIT_TAG "release-1.11.0"
SOURCE_DIR "${EP_BASE_DIR}/googletest-src"
BINARY_DIR "${EP_BASE_DIR}/googletest-build"
CMAKE_CACHE_ARGS
Expand Down
2 changes: 1 addition & 1 deletion examples/nn/1_mnist/1_mnist_mlp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int main(int argc, char **argv) {

// Settings
int epochs = (testing) ? 2 : 10;
int batch_size = 200;
int batch_size = 100;
int num_classes = 10;

// Define network
Expand Down
27 changes: 20 additions & 7 deletions examples/nn/1_mnist/7_mnist_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,33 @@ using namespace eddl;
//////////////////////////////////

int main(int argc, char **argv) {

// Settings
int epochs = 10;
int batch_size = 100;
int num_classes = 10;
bool testing = false;
bool use_cpu = false;
int num_cpu_threads = -1; // -1 = the maximum available cores

for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "--testing") == 0) testing = true;
else if (strcmp(argv[i], "--cpu") == 0) use_cpu = true;
if (strcmp(argv[i], "--testing") == 0) {
testing = true;
epochs = 2;
} else if (strcmp(argv[i], "--cpu") == 0) {
use_cpu = true;
} else if (strcmp(argv[i], "--threads") == 0) {
num_cpu_threads = atoi(argv[++i]);
} else if (strcmp(argv[i], "--epochs") == 0) {
epochs = atoi(argv[++i]);
} else if (strcmp(argv[i], "--batch-size") == 0) {
batch_size = atoi(argv[++i]);
}
}

// Download mnist
download_mnist();

// Settings
int epochs = (testing) ? 2 : 10;
int batch_size = 100;
int num_classes = 10;

// Define network
layer in = Input({784});
Expand All @@ -62,7 +75,7 @@ int main(int argc, char **argv) {

compserv cs = nullptr;
if (use_cpu) {
cs = CS_CPU();
cs = CS_CPU(num_cpu_threads);
} else {
cs = CS_GPU({1}, "full_mem"); // one GPU
// cs = CS_GPU({1,1},100); // two GPU with weight sync every 100 batches
Expand Down
4 changes: 2 additions & 2 deletions formulas/brew/eddl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
class Eddl < Formula
desc "European Distributed Deep Learning Library (EDDL)"
homepage "https://github.com/deephealthproject/eddl"
url "https://github.com/deephealthproject/eddl/archive/v1.0.2a.tar.gz"
sha256 "70d6067d44cb547e218236e5bb72faf45f602a7b8214f869626ca47f241481a0"
url "https://github.com/deephealthproject/eddl/archive/v1.1b.tar.gz"
sha256 "b9fe2bdc63808ae8e1a8eec96f66106c49b7a5ce9ee32ffe17fd6cf9d1b2c4ec"

depends_on "cmake" => :build
depends_on "eigen" => :build
Expand Down
2 changes: 1 addition & 1 deletion formulas/conda/eddl/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ echo "CPU_COUNT=$CPU_COUNT"
echo "#################################################"

# Build makefiles
mkdir build && cd build/ && cmake .. -DBUILD_TARGET=CPU \
mkdir build && cd build/ && cmake .. -DBUILD_TARGET=CUDNN \
-DBUILD_SUPERBUILD=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_TESTS=OFF \
Expand Down
4 changes: 2 additions & 2 deletions formulas/conda/eddl/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set name = "eddl-cpu" %} # eddl-cpu, eddl-gpu, eddl-cudnn
{% set name = "eddl-cudnn" %} # eddl-cpu, eddl-gpu, eddl-cudnn
{% set version = "1.1b" %}
{% set sha256 = "534ca4bd5e83236c164a26a058e08df971d28c0ae5b32674bec364ae0370843a" %}
{% set sha256 = "b9fe2bdc63808ae8e1a8eec96f66106c49b7a5ce9ee32ffe17fd6cf9d1b2c4ec" %}

package:
name: {{ name|lower }}
Expand Down
11 changes: 7 additions & 4 deletions scripts/install/install_gtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ sudo apt-get update
sudo apt-get wget

# Build and install
wget https://github.com/google/googletest/archive/release-1.10.0.tar.gz
tar -zxvf release-1.10.0.tar.gz
cd googletest-release-1.10.0 && mkdir build && \
#wget https://github.com/google/googletest/archive/release-1.10.0.tar.gz
#tar -zxvf release-1.10.0.tar.gz
#cd googletest-release-1.10.0 && mkdir build && \
wget https://github.com/google/googletest/archive/release-1.11.0.tar.gz
tar -zxvf release-1.11.0.tar.gz
cd googletest-release-1.11.0 && mkdir build && \
cd build && cmake .. && sudo make -j$(nproc) install

# Build and install
#sudo apt-get install -y libgtest-dev
#cd /usr/src/gtest
#cmake CMakeLists.txt
#make -j$(nproc)
#cp *.a /usr/lib
#cp *.a /usr/lib
14 changes: 10 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set_property(CACHE BUILD_TARGET PROPERTY STRINGS CPU GPU CUDNN FPGA)

# Initializations (Local's scope)
SET(USE_OPENMP OFF)
SET(USE_RISCV OFF)
SET(USE_CUDA OFF)
SET(USE_CUDNN OFF)
SET(USE_FPGA OFF)
Expand All @@ -20,6 +21,8 @@ SET(USE_PROTOBUF OFF)
# Device specific setup
string(TOUPPER ${BUILD_TARGET} BUILD_TARGET) # Detect cpu, Cpu, CPU,...
if(${BUILD_TARGET} STREQUAL "CPU")
elseif(${BUILD_TARGET} STREQUAL "RISCV")
SET(USE_RISCV ON) # Local's scope
elseif(${BUILD_TARGET} STREQUAL "GPU" OR ${BUILD_TARGET} STREQUAL "CUDA")
SET(USE_CUDA ON) # Local's scope
elseif(${BUILD_TARGET} STREQUAL "CUDNN")
Expand Down Expand Up @@ -122,6 +125,11 @@ endif()
########################## COMPILE FOR RISK-V #############################
###########################################################################

if(USE_RISCV)
set(CMAKE_C_FLAGS_RELEASE "-O2 -march=rv64imafdc -mabi=lp64d ")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -march=rv64imafdc -mabi=lp64d ")
endif()

if(RISKV_COMPILER_PATH)
message(STATUS "Compiling for Risk-V...")
endif()
Expand Down Expand Up @@ -499,10 +507,8 @@ if(USE_FPGA)
message(STATUS "OpenCL include: " ${OpenCL_INCLUDE_DIRS} )
message(STATUS "OpenCL libraries: " ${OpenCL_LIBRARIES} )
endif()
if(RISKV_COMPILER_PATH)
message(STATUS "-------------------------------------------" )
message(STATUS "Risk-V compiler: " ${RISKV_COMPILER_PATH} )
endif()
message(STATUS "-------------------------------------------" )
message(STATUS "RISCV enabled: " ${USE_RISCV} )
message(STATUS "-------------------------------------------" )
message(STATUS "Eigen3 root dir: " ${Eigen3_DIR} )
message(STATUS "Eigen3 include: " ${EIGEN3_INCLUDE_DIR} )
Expand Down
16 changes: 11 additions & 5 deletions src/descriptors/descriptor_conv2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ ConvolDescriptor::~ConvolDescriptor(){
delete gpuOB;
}
}
#else
cudnnDestroyTensorDescriptor(xDesc);
cudnnDestroyTensorDescriptor(yDesc);
#endif
#endif

Expand Down Expand Up @@ -219,8 +222,7 @@ void ConvolDescriptor::build(Tensor *A) {
convolution_mode, data_type);

cudnnCreateTensorDescriptor(&xDesc);
cudnnSetTensor4dDescriptor(xDesc, tensor_format, data_type,
in,iz,ir,ic);
cudnnSetTensor4dDescriptor(xDesc, tensor_format, data_type, in,iz,ir,ic);

cudnnCreateFilterDescriptor(&wDesc);
cudnnSetFilter4dDescriptor(wDesc, data_type, tensor_format, nk, kz, kr, kc);
Expand Down Expand Up @@ -264,11 +266,15 @@ void ConvolDescriptor::resize(int b)
#endif

#ifdef cCUDNN
cudnnSetTensor4dDescriptor(xDesc, tensor_format, data_type,
b,iz,ir,ic);
cudnnDestroyTensorDescriptor(xDesc);
cudnnDestroyTensorDescriptor(yDesc);

cudnnCreateTensorDescriptor(&xDesc);
cudnnCreateTensorDescriptor(&yDesc);
cudnnSetTensor4dDescriptor(yDesc, tensor_format, data_type, O->shape[0], O->shape[1],O->shape[2],O->shape[3]);

cudnnSetTensor4dDescriptor(xDesc, tensor_format, data_type, b,iz,ir,ic);
cudnnSetTensor4dDescriptor(yDesc, tensor_format, data_type, b, O->shape[1],O->shape[2],O->shape[3]);

cudnn_env_init = -1;
cudnn_conv_back_init = -1;

Expand Down
12 changes: 8 additions & 4 deletions src/descriptors/descriptor_conv3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,19 @@ void ConvolDescriptor3D::resize(int b)
#endif

#ifdef cCUDNN
cudnnDestroyTensorDescriptor(xDesc);
cudnnDestroyTensorDescriptor(yDesc);

cudnnCreateTensorDescriptor(&xDesc);
cudnnCreateTensorDescriptor(&yDesc);

int dims[5] = {b, iz, id, ir, ic};
int str[5] = {iz*id*ir*ic,id*ir*ic,ir*ic,ic,1};
cudnnSetTensorNdDescriptor(xDesc, /*tensor_format,*/ data_type,5,dims,str);
cudnnSetTensorNdDescriptor(xDesc, /*tensor_format,*/ data_type,5,dims,str);

int ydims[5] = {b,z,d,r,c};
int ystr[5] = {z*d*r*c, d*r*c, r*c, c, 1};
cudnnSetTensorNdDescriptor(yDesc, /*tensor_format,*/ data_type, 5, ydims, ystr);

//cudnnSetTensor4dDescriptor(yDesc, tensor_format, data_type, O->shape[0], O->shape[1],O->shape[2],O->shape[3]);
cudnnSetTensorNdDescriptor(yDesc, /*tensor_format,*/ data_type, 5, ydims, ystr);

cudnn_env_init = -1;
cudnn_conv_back_init = -1;
Expand Down
15 changes: 9 additions & 6 deletions src/descriptors/descriptor_pool2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ void PoolDescriptor::build(Tensor *A) {
tensor_format = CUDNN_TENSOR_NCHW; // CUDNN_TENSOR_NHWC

cudnnCreateTensorDescriptor(&xDesc);
cudnnSetTensor4dDescriptor(xDesc, tensor_format, data_type,
in,iz,ir,ic);
cudnnSetTensor4dDescriptor(xDesc, tensor_format, data_type, in,iz,ir,ic);
cudnnCreateTensorDescriptor(&yDesc);
cudnnSetTensor4dDescriptor(yDesc, tensor_format, data_type, in, z,r,c);
}
Expand All @@ -146,10 +145,14 @@ void PoolDescriptor::resize(int b) {
this->O->resize(b);
#ifdef cCUDNN
if(!this->O->isCPU()){
cudnnSetTensor4dDescriptor(xDesc, tensor_format, data_type,
b,iz,ir,ic);
cudnnCreateTensorDescriptor(&yDesc);
cudnnSetTensor4dDescriptor(yDesc, tensor_format, data_type, O->shape[0], O->shape[1],O->shape[2],O->shape[3]);
cudnnDestroyTensorDescriptor(xDesc);
cudnnDestroyTensorDescriptor(yDesc);

cudnnCreateTensorDescriptor(&xDesc);
cudnnCreateTensorDescriptor(&yDesc);

cudnnSetTensor4dDescriptor(xDesc, tensor_format, data_type, b,iz,ir,ic);
cudnnSetTensor4dDescriptor(yDesc, tensor_format, data_type, b, O->shape[1],O->shape[2],O->shape[3]);
}
#endif
// if (!mem_level) { D->resize(b); }
Expand Down
17 changes: 11 additions & 6 deletions src/descriptors/descriptor_pool3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,19 @@ void PoolDescriptor3D::resize(int b) {
O->resize(b);
#ifdef cCUDNN
if(!O->isCPU()){
int dims[5] = {b, iz, id, ir, ic};
int str[5] = {iz*id*ir*ic,id*ir*ic,ir*ic,ic,1};
cudnnSetTensorNdDescriptor(xDesc, data_type,5,dims,str);
cudnnDestroyTensorDescriptor(xDesc);
cudnnDestroyTensorDescriptor(yDesc);

int ydims[5] = {b,z,d,r,c};
int ystr[5] = {z*d*r*c, d*r*c, r*c, c, 1};
cudnnSetTensorNdDescriptor(yDesc, data_type, 5, ydims, ystr);
cudnnCreateTensorDescriptor(&xDesc);
cudnnCreateTensorDescriptor(&yDesc);

int dims[5] = {b, iz, id, ir, ic};
int str[5] = {iz*id*ir*ic,id*ir*ic,ir*ic,ic,1};
cudnnSetTensorNdDescriptor(xDesc, data_type,5,dims,str);

int ydims[5] = {b,z,d,r,c};
int ystr[5] = {z*d*r*c, d*r*c, r*c, c, 1};
cudnnSetTensorNdDescriptor(yDesc, data_type, 5, ydims, ystr);
}


Expand Down
2 changes: 2 additions & 0 deletions src/layers/conv/layer_conv1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ void LConv1D::mem_delta(){
if(this->verbosity_level >= 2) {
std::cout << "Booked delta for: " + this->name << std::endl;
}
} else {
this->delta->resize(this->output->shape[0]);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/layers/conv/layer_conv2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ void LConv::mem_delta(){
if(this->verbosity_level >= 2) {
std::cout << "Booked delta for: " + this->name << std::endl;
}
} else {
this->delta->resize(this->output->shape[0]);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/layers/conv/layer_conv3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ void LConv3D::mem_delta(){
if(this->verbosity_level >= 2) {
std::cout << "Booked delta for: " + this->name << std::endl;
}
} else {
this->delta->resize(this->output->shape[0]);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/layers/pool/layer_pool1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ void LPool1D::mem_delta(){
if(this->verbosity_level >= 2) {
std::cout << "Booked delta for: " + this->name << std::endl;
}
} else {
this->delta->resize(this->output->shape[0]);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/layers/pool/layer_pool2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ void LPool::mem_delta(){
if(this->verbosity_level >= 2) {
std::cout << "Booked delta for: " + this->name << std::endl;
}
} else {
this->delta->resize(this->output->shape[0]);
}
}

Expand Down
Loading

0 comments on commit d708158

Please sign in to comment.