Skip to content

Commit a6c5aa5

Browse files
committed
Auto merge of #96 - autumnai:feat/serialization, r=MichaelHirn
feat/serialization: add serialization WIP, the commit for deserialization is still missing because it needs a bit of polish Will resolve #14, #15
2 parents de0eb7c + df7c9d8 commit a6c5aa5

16 files changed

+862
-33
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
target
22
Cargo.lock
3+
4+
mynetwork

.travis.yml

+25-9
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,30 @@ script:
2828
travis-cargo --only stable doc -- --no-default-features --features $FEATURES
2929
addons:
3030
apt:
31+
sources:
32+
- ubuntu-toolchain-r-test
3133
packages:
32-
- libcurl4-openssl-dev
33-
- libelf-dev
34-
- libdw-dev
35-
- libblas-dev
36-
- fglrx
37-
- opencl-headers
38-
- binutils-dev
39-
- nvidia-opencl-dev
40-
34+
- libcurl4-openssl-dev
35+
- libelf-dev
36+
- libdw-dev
37+
- libblas-dev
38+
- fglrx
39+
- opencl-headers
40+
- binutils-dev
41+
- nvidia-opencl-dev
42+
- gcc-4.8
43+
- g++-4.8
44+
install:
45+
- git clone https://github.com/kentonv/capnproto.git
46+
- cd capnproto/c++
47+
- git checkout tags/v0.5.3
48+
- ./setup-autotools.sh
49+
- autoreconf -i
50+
- ./configure --disable-shared
51+
- make -j5
52+
- export PATH="$PATH:$(pwd)"
53+
- export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(pwd)"
54+
- cd ../..
4155
after_success:
4256
- travis-cargo doc-upload
4357
- travis-cargo coveralls --no-sudo --verify
@@ -46,6 +60,8 @@ notifications:
4660
on_success: never
4761
env:
4862
global:
63+
- CC=gcc-4.8
64+
- CXX=g++-4.8
4965
- secure: QcJ9u0BrVpvjYnerd/3dukvM+GLFQNikIoDHhtKjVenuM2ozZtW6+/RyyXVC1YMh/SghwTnu4Kcnv1sdmwuiC5KWdPoppfalXdxafPkl5PGEfTOexe6L5UAJNW6BdA4lbRKM3xnaUg0Guq6x6tD/zdABIkh8nym/gRLGKT40e9Xitkf6wUQqPBHTGZimip59qg5Fty8lAD48pCBEXynJm+ihA2tz6EDhp0/7wvieHyEl/FqNwvUL5+Z9EeTzEJfKNF8PA5DTHkgeXgeCnWKLm8cCdPEziRZlgdQtvIW27oZBkNTQGHyqI9/tVYhaW4AeKstzE5BoJuyRzmerWYRQCNiz8bgyAjc5HnpWLJPmPSFaGBWTRzwYwUk/iOUP4YEZiN3p0Xj1sKgSB0TA2AjKWND7cufwjrW8NdPdZ3hURVOnM8DHYSQMm2HOfbUNnkw+P5M8n+flT2HKWFdnPhJ3n12rDlLYdHeg9PQ3emJ6kE8Y/jrNT+6yZRrSwLQnsV0uU8Ii44MFQHpdUOGuOIxZFGh9rjKsUwhruUpGtbwI4FWPOqiQJvIaBFY1IUjIVlVCZevvIG3fPXvPksIEKwK93hM/ThDi2PLq2qwBpA87RNfKxDG4S0aR2j19IG+ludbpPcP95mYFVnGCb4rpj44iZoCifC8c9tVqC4L85hEGzik=
5066
matrix:
5167
- FEATURES=travis

Cargo.toml

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ readme = "README.md"
1313
keywords = ["deep-learning", "neural-networks", "machine-learning", "framework"]
1414
license = "MIT OR Apache-2.0"
1515

16+
build = "build.rs"
17+
1618
[dependencies]
1719
collenchyma = { version = "0.0.8", default-features = false, features = ["native"] } # native feature to read/write data into tensors
1820
collenchyma-blas = { version = "0.2.0", default-features = false, features = ["native"] } # only compiles with native feature
@@ -22,10 +24,15 @@ log = "0.3.2"
2224
rand = "0.3.0"
2325
num = "0.1"
2426

25-
clippy = { version = "0.0.41", optional = true }
27+
capnp = "0.6.2"
2628

2729
timeit = "0.1.2"
2830

31+
clippy = { version = "0.0.41", optional = true }
32+
33+
[build-dependencies]
34+
capnpc = "0.6.1"
35+
2936
[dev-dependencies]
3037
env_logger = "0.3"
3138

build.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern crate capnpc;
2+
3+
fn main() {
4+
::capnpc::compile("capnp", &["capnp/leaf.capnp"]).unwrap();
5+
}

capnp/leaf.capnp

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
@0x8316e0f30c445924;
2+
3+
# The structs here try to mirror all the *Config structs as close as possible.
4+
# Before changing anything take a look at https://capnproto.org/language.html#evolving-your-protocol
5+
6+
struct Weight {
7+
name @0 :Text;
8+
tensor @1 :Tensor;
9+
}
10+
11+
struct Tensor {
12+
shape @0 :List(UInt64);
13+
data @1 :List(Float32);
14+
}
15+
16+
struct Layer {
17+
name @0 :Text;
18+
config @1 :LayerConfig;
19+
weightsData @2 :List(Weight);
20+
}
21+
22+
struct LayerConfig {
23+
name @0 :Text;
24+
layerType :union {
25+
# Common layers
26+
convolution @1 :ConvolutionConfig;
27+
linear @2 :LinearConfig;
28+
logSoftmax @3 :Void;
29+
pooling @4 :PoolingConfig;
30+
sequential @5 :SequentialConfig;
31+
softmax @6 :Void;
32+
# Activation layers
33+
relu @7 :Void;
34+
sigmoid @8 :Void;
35+
# Loss layers
36+
negativeLogLikelihood @9 :NegativeLogLikelihoodConfig;
37+
# Utility layers
38+
reshape @10 :ReshapeConfig;
39+
}
40+
41+
outputs @11 :List(Text);
42+
inputs @12 :List(Text);
43+
params @13 :List(WeightConfig);
44+
propagateDown @14 :List(Bool);
45+
}
46+
47+
# TODO: incomplete since WeightConfig isn't really used internally in Leaf.
48+
struct WeightConfig {
49+
name @0 :Text;
50+
}
51+
52+
struct ConvolutionConfig {
53+
numOutput @0 :UInt64;
54+
filterShape @1 :List(UInt64);
55+
stride @2 :List(UInt64);
56+
padding @3 :List(UInt64);
57+
}
58+
59+
struct LinearConfig {
60+
outputSize @0 :UInt64;
61+
}
62+
63+
struct PoolingConfig {
64+
mode @0 :PoolingMode;
65+
filterShape @1 :List(UInt64);
66+
stride @2 :List(UInt64);
67+
padding @3 :List(UInt64);
68+
}
69+
70+
enum PoolingMode {
71+
max @0;
72+
average @1; # not implemented yet, but we can't create a single variant enum so this is better than a meaningless "Dummy" value.
73+
}
74+
75+
struct SequentialConfig {
76+
layers @0 :List(LayerConfig);
77+
inputs @1 :List(ShapedInput);
78+
forceBackward @2 :Bool;
79+
}
80+
81+
struct ShapedInput {
82+
name @0 :Text;
83+
shape @1 :List(UInt64);
84+
}
85+
86+
struct NegativeLogLikelihoodConfig {
87+
numClasses @0 :UInt64;
88+
}
89+
90+
struct ReshapeConfig {
91+
shape @0 :List(UInt64);
92+
}

src/capnp_util.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Provides functionality for Cap'n Proto (de)serialization.
2+
3+
pub trait CapnpWrite<'a> {
4+
/// The Builder that was autogenerated by capnp.
5+
type Builder;
6+
7+
/// Write the struct into the message that is being built by the Builder.
8+
fn write_capnp(&self, builder: &mut Self::Builder);
9+
}
10+
11+
pub trait CapnpRead<'a> {
12+
/// The Reader that was autogenerated by capnp.
13+
type Reader;
14+
15+
/// Read the struct from the Reader.
16+
fn read_capnp(reader: Self::Reader) -> Self;
17+
}

0 commit comments

Comments
 (0)