Skip to content

Commit 5ab93fc

Browse files
authored
Merge pull request #261 from deephealthproject/develop
Fixes for the binding (v0.9)
2 parents 7ac88b4 + a99b611 commit 5ab93fc

File tree

10 files changed

+185
-110
lines changed

10 files changed

+185
-110
lines changed

docs/sphinx/source/intro/installation.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,27 @@ You can use one of the following lines according to your needs:
3434
3535
.. note::
3636

37-
- Platforms supported: Linux x86/x64 and MacOS
37+
- Platforms supported: Linux and MacOS
3838

39-
.. tab:: GPU
39+
.. tab:: GPU (CUDA)
4040

4141
.. code:: bash
4242
4343
conda install -c deephealth eddl-gpu
4444
4545
.. note::
4646

47-
- Platforms supported: Linux x86/x64
47+
- Platforms supported: Linux
48+
49+
.. tab:: GPU (cuDNN)
50+
51+
.. code:: bash
52+
53+
conda install -c deephealth eddl-cudnn
54+
55+
.. note::
56+
57+
- Platforms supported: Linux
4858

4959

5060
.. image:: ../_static/images/logos/homebrew.svg

examples/nn/4_NLP/5_nlp_text_generation.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,12 @@ int main(int argc, char **argv) {
8686

8787
setDecoder(ldecin);
8888

89+
model old_net = net;
90+
8991
net = Model({image_in}, {out});
9092

93+
delete old_net;
94+
9195
plot(net, "model.pdf");
9296

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

115119

116-
117120
// Load dataset
118121
Tensor *x_train=Tensor::load("flickr_trX.bin","bin");
119122
//x_train->info(); //1000,256,256,3

formulas/brew/eddl.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
class Eddl < Formula
55
desc "European Distributed Deep Learning Library (EDDL)"
66
homepage "https://github.com/deephealthproject/eddl"
7-
url "https://github.com/deephealthproject/eddl/archive/v0.8.3a.tar.gz"
8-
sha256 "3d0678b4e00b9a5fb9c3905cf5bd3f5daa596684af47d1e77fbabbfd82f4e064"
7+
url "https://github.com/deephealthproject/eddl/archive/v0.9a.tar.gz"
8+
sha256 "93372aca9133f847c9dd2dd678a2107e9424d512e806929065fbe2a17270a425"
99

1010
depends_on "cmake" => :build
1111
depends_on "eigen" => :build
1212
depends_on "protobuf" => :build
13+
depends_on "zlib" => :build
14+
depends_on "openssl@1.1" => :build
1315
depends_on "graphviz" => :build
1416
depends_on "wget" => :build
1517

formulas/conda/eddl/build.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,32 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
1111

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

18+
# Prints vars
19+
echo "#################################################"
20+
echo "##### CONDA BUILD CONSTANTS #####################"
21+
echo "#################################################"
22+
echo "PREFIX=$PREFIX"
23+
echo "CMAKE_LIBRARY_PATH=$CMAKE_LIBRARY_PATH"
24+
echo "CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH"
25+
echo "SRC_DIR=$SRC_DIR"
26+
echo "CC=$CC"
27+
echo "CXX=$CXX"
28+
echo "CPU_COUNT=$CPU_COUNT"
29+
echo "#################################################"
1830

1931
# Build makefiles
20-
mkdir build
21-
cd build/
2232
cmake -DBUILD_TARGET=CPU \
2333
-DBUILD_SUPERBUILD=OFF \
2434
-DBUILD_EXAMPLES=OFF \
2535
-DBUILD_TESTS=OFF \
36+
-DCMAKE_C_COMPILER=$CC \
37+
-DCMAKE_CXX_COMPILER=$CXX \
38+
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
39+
-DCMAKE_PREFIX_PATH=$PREFIX \
2640
-DCMAKE_INSTALL_PREFIX=$PREFIX \
2741
$SRC_DIR
2842

formulas/conda/eddl/meta.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% set name = "eddl-cpu" %} # If this is a package for GPU, use: "eddl-gpu"
2-
{% set version = "0.8.3a" %}
3-
{% set sha256 = "3d0678b4e00b9a5fb9c3905cf5bd3f5daa596684af47d1e77fbabbfd82f4e064" %}
2+
{% set version = "0.9a" %}
3+
{% set sha256 = "93372aca9133f847c9dd2dd678a2107e9424d512e806929065fbe2a17270a425" %}
44

55
package:
66
name: {{ name|lower }}
@@ -19,20 +19,22 @@ requirements:
1919
build:
2020
- {{ compiler('cxx') }}
2121
host:
22-
- cmake>=3.9.2
22+
- cmake>=3.17.2
2323
- eigen==3.3.7
2424
- protobuf==3.11.4
2525
- libprotobuf==3.11.4 # We need to avoid problems with paths (idk why)
26-
- cudatoolkit
27-
- graphviz # Build & Run
26+
- zlib==1.2.11
27+
- openssl==1.1.1i
28+
- graphviz # Build & Run (versions can be problematic)
2829
- wget
2930
run:
30-
- cmake>=3.9.2
31+
- cmake>=3.17.2
3132
- eigen==3.3.7
3233
- protobuf==3.11.4
3334
- libprotobuf==3.11.4 # We need to avoid problems with paths (idk why)
34-
- cudatoolkit
35-
- graphviz # Build & Run
35+
- zlib==1.2.11
36+
- openssl==1.1.1i
37+
- graphviz # Build & Run (versions can be problematic)
3638
- wget
3739

3840
test:

include/eddl/layers/layer.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Net;
3131

3232
class Layer {
3333
private:
34-
void * my_owner;
34+
int reference_counter;
3535

3636
public:
3737
string name;
@@ -132,9 +132,8 @@ class Layer {
132132

133133
virtual void enable_distributed() {}
134134

135-
bool set_my_owner(void * net);
136-
bool is_my_owner(void * net);
137-
void * get_my_owner();
135+
int decrease_and_get_reference_counter();
136+
void increase_reference_counter();
138137
};
139138

140139

src/layers/layer.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Layer::Layer(string name, int dev, int mem) {
4848
// init = new IGlorotNormal(1234);
4949
this->init = new IGlorotUniform(1234); // Has problems with the drive dataset
5050

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

5454
Layer::~Layer(){
@@ -251,24 +251,13 @@ void Layer::copy(Layer *l2){
251251
}
252252
}
253253

254-
bool Layer::set_my_owner(void * net)
254+
void Layer::increase_reference_counter()
255255
{
256-
if (this->my_owner == nullptr) {
257-
this->my_owner = net;
258-
return true;
259-
} else {
260-
return false;
261-
}
256+
reference_counter++;
262257
}
263-
264-
bool Layer::is_my_owner(void * net)
265-
{
266-
return this->my_owner == net;
267-
}
268-
269-
void * Layer::get_my_owner()
258+
int Layer::decrease_and_get_reference_counter()
270259
{
271-
return this->my_owner;
260+
return --reference_counter;
272261
}
273262

274263
////////////////////////////////////

src/net/net.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,8 @@ Net::Net(vlayer in, vlayer out):Net() {
7676
// Set input/outlayer
7777
//lin = in;
7878
//lout = out;
79-
for (auto l : in) {
80-
lin.push_back(l);
81-
l->set_my_owner(this);
82-
}
83-
for (auto l : out) {
84-
lout.push_back(l);
85-
l->set_my_owner(this);
86-
}
79+
for (auto l : in) lin.push_back(l);
80+
for (auto l : out) lout.push_back(l);
8781

8882
// Walk through the pointers of all layers, to get a plain
8983
// vector with all the layers
@@ -111,9 +105,11 @@ Net::Net(vlayer in, vlayer out):Net() {
111105
// It is important that layers vector keep the forward sort
112106
fts();
113107
while (layers.size()) layers.pop_back();
114-
for(auto l: vfts ) layers.push_back(l);
108+
for(auto l: vfts ) {
109+
l->increase_reference_counter();
110+
layers.push_back(l);
111+
}
115112
while (vfts.size()) vfts.pop_back();
116-
117113
}
118114

119115

@@ -160,7 +156,7 @@ Net::~Net(){
160156
}
161157
}
162158

163-
if (snets[0] != this){
159+
if (snets.size() == 0 || snets[0] != this){
164160
if (this->optimizer != nullptr && this->do_optimizer_delete){
165161
delete this->optimizer;
166162
}
@@ -176,24 +172,22 @@ Net::~Net(){
176172
for(int i=0;i<snets.size();i++){
177173
for(int j=0;j<snets[i]->layers.size();j++) {
178174
if (snets[i]->layers[j]!=nullptr) {
179-
//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);
180-
if (snets[i]->layers[j]->is_my_owner(this) || snets[i]->layers[j]->is_my_owner(snets[i])) {
175+
if (snets[i]->layers[j]->decrease_and_get_reference_counter() == 0) {
181176
delete snets[i]->layers[j];
182-
snets[i]->layers[j] = nullptr;
183177
}
178+
snets[i]->layers[j] = nullptr;
184179
}
185180
}
186181
}
187182

188183
// net running on device != CPU
189184
// clean also CPU mem
190-
if (snets[0]!=this){
185+
if (snets.size() == 0 || snets[0]!=this){
191186
for(int j=0;j<layers.size();j++) {
192-
//fprintf(stderr, "%s(%d) %d : %p %p\n", __FILE__, __LINE__, j, layers[j]->get_my_owner(), this);
193-
if (layers[j]->is_my_owner(this)) {
187+
if (layers[j]->decrease_and_get_reference_counter() == 0) {
194188
delete layers[j];
195-
layers[j] = nullptr;
196189
}
190+
layers[j] = nullptr;
197191
}
198192
}
199193

@@ -237,7 +231,6 @@ void Net::walk(Layer *l,vlayer lout) {
237231
if (!inNetF(l)) {
238232
l->net=this;
239233
layersf.push_back(l);
240-
l->set_my_owner(this);
241234
}
242235
else return;
243236

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

254247
if (!inNetB(l)) {
255248
layersb.push_back(l);
256-
l->set_my_owner(this);
257249
l->net=this;
258250
}
259251
else return;

src/net/net_build.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ void Net::removeLayer(string lname)
479479
for(int k=0;k<p->child.size();k++) {
480480
if (p->child[k]==l) {
481481
p->child.erase(p->child.begin() + k);
482+
p->lout--;
483+
break;
482484
}
483485
}//child
484486
// create new outputs from parents
@@ -489,7 +491,10 @@ void Net::removeLayer(string lname)
489491
//layers.erase(layers.begin() + i);
490492
for(int j=0;j<lout.size();j++) {
491493
cout<<lout[j]->name<<endl;
492-
if (lout[j]->name==lname) lout.erase(lout.begin()+j);
494+
if (lout[j]->name==lname) {
495+
lout.erase(lout.begin()+j);
496+
break;
497+
}
493498
}
494499
// remove lname from list of layers
495500
layers.erase(layers.begin() + i);

0 commit comments

Comments
 (0)