Skip to content

Commit

Permalink
Merge pull request #261 from deephealthproject/develop
Browse files Browse the repository at this point in the history
Fixes for the binding (v0.9)
  • Loading branch information
salvacarrion authored Feb 23, 2021
2 parents 7ac88b4 + a99b611 commit 5ab93fc
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 110 deletions.
16 changes: 13 additions & 3 deletions docs/sphinx/source/intro/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,27 @@ You can use one of the following lines according to your needs:
.. note::

- Platforms supported: Linux x86/x64 and MacOS
- Platforms supported: Linux and MacOS

.. tab:: GPU
.. tab:: GPU (CUDA)

.. code:: bash
conda install -c deephealth eddl-gpu
.. note::

- Platforms supported: Linux x86/x64
- Platforms supported: Linux

.. tab:: GPU (cuDNN)

.. code:: bash
conda install -c deephealth eddl-cudnn
.. note::

- Platforms supported: Linux


.. image:: ../_static/images/logos/homebrew.svg
Expand Down
5 changes: 4 additions & 1 deletion examples/nn/4_NLP/5_nlp_text_generation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ int main(int argc, char **argv) {

setDecoder(ldecin);

model old_net = net;

net = Model({image_in}, {out});

delete old_net;

plot(net, "model.pdf");

optimizer opt=adam(0.01);
Expand All @@ -113,7 +117,6 @@ int main(int argc, char **argv) {
summary(net);



// Load dataset
Tensor *x_train=Tensor::load("flickr_trX.bin","bin");
//x_train->info(); //1000,256,256,3
Expand Down
6 changes: 4 additions & 2 deletions formulas/brew/eddl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
class Eddl < Formula
desc "European Distributed Deep Learning Library (EDDL)"
homepage "https://github.com/deephealthproject/eddl"
url "https://github.com/deephealthproject/eddl/archive/v0.8.3a.tar.gz"
sha256 "3d0678b4e00b9a5fb9c3905cf5bd3f5daa596684af47d1e77fbabbfd82f4e064"
url "https://github.com/deephealthproject/eddl/archive/v0.9a.tar.gz"
sha256 "93372aca9133f847c9dd2dd678a2107e9424d512e806929065fbe2a17270a425"

depends_on "cmake" => :build
depends_on "eigen" => :build
depends_on "protobuf" => :build
depends_on "zlib" => :build
depends_on "[email protected]" => :build
depends_on "graphviz" => :build
depends_on "wget" => :build

Expand Down
22 changes: 18 additions & 4 deletions formulas/conda/eddl/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,32 @@ if [[ "$OSTYPE" == "darwin"* ]]; then

# If I don't do this, I get errors like: "undefined reference to `expf@GLIBC_2.27'"
elif [[ "$OSTYPE" == "linux"* ]]; then
CXX=g++
CC=gcc
CXX=g++-7
CC=gcc-7
fi

# Prints vars
echo "#################################################"
echo "##### CONDA BUILD CONSTANTS #####################"
echo "#################################################"
echo "PREFIX=$PREFIX"
echo "CMAKE_LIBRARY_PATH=$CMAKE_LIBRARY_PATH"
echo "CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH"
echo "SRC_DIR=$SRC_DIR"
echo "CC=$CC"
echo "CXX=$CXX"
echo "CPU_COUNT=$CPU_COUNT"
echo "#################################################"

# Build makefiles
mkdir build
cd build/
cmake -DBUILD_TARGET=CPU \
-DBUILD_SUPERBUILD=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_TESTS=OFF \
-DCMAKE_C_COMPILER=$CC \
-DCMAKE_CXX_COMPILER=$CXX \
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
-DCMAKE_PREFIX_PATH=$PREFIX \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
$SRC_DIR

Expand Down
18 changes: 10 additions & 8 deletions formulas/conda/eddl/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set name = "eddl-cpu" %} # If this is a package for GPU, use: "eddl-gpu"
{% set version = "0.8.3a" %}
{% set sha256 = "3d0678b4e00b9a5fb9c3905cf5bd3f5daa596684af47d1e77fbabbfd82f4e064" %}
{% set version = "0.9a" %}
{% set sha256 = "93372aca9133f847c9dd2dd678a2107e9424d512e806929065fbe2a17270a425" %}

package:
name: {{ name|lower }}
Expand All @@ -19,20 +19,22 @@ requirements:
build:
- {{ compiler('cxx') }}
host:
- cmake>=3.9.2
- cmake>=3.17.2
- eigen==3.3.7
- protobuf==3.11.4
- libprotobuf==3.11.4 # We need to avoid problems with paths (idk why)
- cudatoolkit
- graphviz # Build & Run
- zlib==1.2.11
- openssl==1.1.1i
- graphviz # Build & Run (versions can be problematic)
- wget
run:
- cmake>=3.9.2
- cmake>=3.17.2
- eigen==3.3.7
- protobuf==3.11.4
- libprotobuf==3.11.4 # We need to avoid problems with paths (idk why)
- cudatoolkit
- graphviz # Build & Run
- zlib==1.2.11
- openssl==1.1.1i
- graphviz # Build & Run (versions can be problematic)
- wget

test:
Expand Down
7 changes: 3 additions & 4 deletions include/eddl/layers/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Net;

class Layer {
private:
void * my_owner;
int reference_counter;

public:
string name;
Expand Down Expand Up @@ -132,9 +132,8 @@ class Layer {

virtual void enable_distributed() {}

bool set_my_owner(void * net);
bool is_my_owner(void * net);
void * get_my_owner();
int decrease_and_get_reference_counter();
void increase_reference_counter();
};


Expand Down
21 changes: 5 additions & 16 deletions src/layers/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Layer::Layer(string name, int dev, int mem) {
// init = new IGlorotNormal(1234);
this->init = new IGlorotUniform(1234); // Has problems with the drive dataset

this->my_owner = nullptr;
this->reference_counter = 0; // accounts how many nets are referencing this layer
}

Layer::~Layer(){
Expand Down Expand Up @@ -251,24 +251,13 @@ void Layer::copy(Layer *l2){
}
}

bool Layer::set_my_owner(void * net)
void Layer::increase_reference_counter()
{
if (this->my_owner == nullptr) {
this->my_owner = net;
return true;
} else {
return false;
}
reference_counter++;
}

bool Layer::is_my_owner(void * net)
{
return this->my_owner == net;
}

void * Layer::get_my_owner()
int Layer::decrease_and_get_reference_counter()
{
return this->my_owner;
return --reference_counter;
}

////////////////////////////////////
Expand Down
32 changes: 12 additions & 20 deletions src/net/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,8 @@ Net::Net(vlayer in, vlayer out):Net() {
// Set input/outlayer
//lin = in;
//lout = out;
for (auto l : in) {
lin.push_back(l);
l->set_my_owner(this);
}
for (auto l : out) {
lout.push_back(l);
l->set_my_owner(this);
}
for (auto l : in) lin.push_back(l);
for (auto l : out) lout.push_back(l);

// Walk through the pointers of all layers, to get a plain
// vector with all the layers
Expand Down Expand Up @@ -111,9 +105,11 @@ Net::Net(vlayer in, vlayer out):Net() {
// It is important that layers vector keep the forward sort
fts();
while (layers.size()) layers.pop_back();
for(auto l: vfts ) layers.push_back(l);
for(auto l: vfts ) {
l->increase_reference_counter();
layers.push_back(l);
}
while (vfts.size()) vfts.pop_back();

}


Expand Down Expand Up @@ -160,7 +156,7 @@ Net::~Net(){
}
}

if (snets[0] != this){
if (snets.size() == 0 || snets[0] != this){
if (this->optimizer != nullptr && this->do_optimizer_delete){
delete this->optimizer;
}
Expand All @@ -176,24 +172,22 @@ Net::~Net(){
for(int i=0;i<snets.size();i++){
for(int j=0;j<snets[i]->layers.size();j++) {
if (snets[i]->layers[j]!=nullptr) {
//fprintf(stderr, "%s(%d) %d %d : %p %p %p %p\n", __FILE__, __LINE__, i, j, snets[i]->layers[j]->get_my_owner(), this, snets[i], rnet);
if (snets[i]->layers[j]->is_my_owner(this) || snets[i]->layers[j]->is_my_owner(snets[i])) {
if (snets[i]->layers[j]->decrease_and_get_reference_counter() == 0) {
delete snets[i]->layers[j];
snets[i]->layers[j] = nullptr;
}
snets[i]->layers[j] = nullptr;
}
}
}

// net running on device != CPU
// clean also CPU mem
if (snets[0]!=this){
if (snets.size() == 0 || snets[0]!=this){
for(int j=0;j<layers.size();j++) {
//fprintf(stderr, "%s(%d) %d : %p %p\n", __FILE__, __LINE__, j, layers[j]->get_my_owner(), this);
if (layers[j]->is_my_owner(this)) {
if (layers[j]->decrease_and_get_reference_counter() == 0) {
delete layers[j];
layers[j] = nullptr;
}
layers[j] = nullptr;
}
}

Expand Down Expand Up @@ -237,7 +231,6 @@ void Net::walk(Layer *l,vlayer lout) {
if (!inNetF(l)) {
l->net=this;
layersf.push_back(l);
l->set_my_owner(this);
}
else return;

Expand All @@ -253,7 +246,6 @@ void Net::walk_back(Layer *l) {

if (!inNetB(l)) {
layersb.push_back(l);
l->set_my_owner(this);
l->net=this;
}
else return;
Expand Down
7 changes: 6 additions & 1 deletion src/net/net_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ void Net::removeLayer(string lname)
for(int k=0;k<p->child.size();k++) {
if (p->child[k]==l) {
p->child.erase(p->child.begin() + k);
p->lout--;
break;
}
}//child
// create new outputs from parents
Expand All @@ -489,7 +491,10 @@ void Net::removeLayer(string lname)
//layers.erase(layers.begin() + i);
for(int j=0;j<lout.size();j++) {
cout<<lout[j]->name<<endl;
if (lout[j]->name==lname) lout.erase(lout.begin()+j);
if (lout[j]->name==lname) {
lout.erase(lout.begin()+j);
break;
}
}
// remove lname from list of layers
layers.erase(layers.begin() + i);
Expand Down
Loading

0 comments on commit 5ab93fc

Please sign in to comment.