-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathREADME
227 lines (164 loc) · 7.75 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
CUV Documentation
0.9.201107041204
Summary
CUV is a C++ template and Python library which makes it easy to use NVIDIA(tm)
CUDA.
Features
Supported Platforms:
• This library was only tested on Ubuntu Karmic, Lucid and Maverick. It uses
mostly standard components (except PyUBLAS) and should run without major
modification on any current linux system.
Supported GPUs:
• By default, code is generated for the lowest compute architecture. We
recommend you change this to match your hardware. Using ccmake you can set
the build variable "CUDA_ARCHITECTURE" for example to -arch=compute_20
• All GT 9800 and GTX 280 and above
• GT 9200 without convolutions. It might need some minor modifications to
make the rest work. If you want to use that card and have problems, just
get in contact.
• On 8800GTS, random numbers and convolutions wont work.
Structure:
• Like for example Matlab, CUV assumes that everything is an n-dimensional
array called "tensor"
• Tensors can have an arbitrary data-type and can be on the host (CPU-memory)
or device (GPU-memory)
• Tensors can be column-major or row-major (1-dimensional tensors are, by
convention, row-major)
• The library defines many functions which may or may not apply to all
possible combinations. Variations are easy to add.
• For convenience, we also wrap some of the functionality provided by Alex
Krizhevsky on his website (http://www.cs.utoronto.ca/~kriz/) with
permission. Thanks Alex for providing your code!
Python Integration
• CUV plays well with python and numpy. That is, once you wrote your fast GPU
functions in CUDA/C++, you can export them using Boost.Python. You can use
Numpy for pre-processing and fancy stuff you have not yet implemented, then
push the Numpy-matrix to the GPU, run your operations there, pull again to
CPU and visualize using matplotlib. Great.
Implemented Functionality
• Simple Linear Algebra for dense vectors and matrices (BLAS level 1,2,3)
• Helpful functors and abstractions
• Sparse matrices in DIA format and matrix-multiplication for these matrices
• I/O functions using boost.serialization
• Fast Random Number Generator
• Up to now, CUV was used to build dense and sparse Neural Networks and
Restricted Boltzmann Machines (RBM), convolutional or locally connected.
Documentation
• Tutorials are available on http://www.ais.uni-bonn.de/~schulz/tag/cuv
• The documentation can be generated from the code or accessed on the
internet: http://www.ais.uni-bonn.de/deep_learning/doc/html/index.html
Contact
• We are eager to help you getting started with CUV and improve the library
continuously! If you have any questions, feel free to contact Hannes Schulz
(schulz at ais dot uni-bonn dot de) or Andreas Mueller (amueller at ais dot
uni-bonn dot de). You can find the website of our group at http://
www.ais.uni-bonn.de/deep_learning/index.html.
Installation
Requirements
For C++ libs, you will need:
• cmake (and cmake-curses-gui for easy configuration)
• libboost-dev >= 1.37
• libblas-dev
• libtemplate-perl -- (we might get rid of this dependency soon)
• NVIDIA CUDA (tm), including SDK. We support versions 3.X and 4.0
• thrust library - included in CUDA since 4.0 (otherwise available from http:
//code.google.com/p/thrust/)
• doxygen (if you want to build the documentation yourself)
For Python Integration, you additionally have to install
• pyublas -- from http://mathema.tician.de/software/pyublas
• python-nose -- for python testing
• python-dev
Optionally, install dependent libraries
• cimg-dev for visualization of matrices (grayscale only, ATM)
Obtaining CUV
You should check out the git repository
$ git clone git://github.com/deeplearningais/CUV.git
Installation Procedure
Building a debug version:
$ cd cuv-version-source
$ mkdir -p build/debug
$ cd build/debug
$ cmake -DCMAKE_BUILD_TYPE=Debug ../../
$ ccmake . # adjust paths to your system (cuda, thrust, pyublas, ...)!
# turn on/off optional libraries (CImg, ...)
$ make -j
$ ctest # run tests to see if it went well
$ sudo make install
$ export PYTHONPATH=`pwd`/src # only if you want python bindings
Building a release version:
$ cd cuv-version-source
$ mkdir -p build/release
$ cd build/release
$ cmake -DCMAKE_BUILD_TYPE=Release ../../
$ ccmake . # adjust paths to your system (cuda, thrust, pyublas, ...)!
# turn on/off optional libraries (CImg, ...)
$ make -j
$ ctest # run tests to see if it went well
$ sudo make install
$ export PYTHONPATH=`pwd`/src # only if you want python bindings
On Debian/Ubuntu systems, you can skip the sudo make install step and instead
do
$ cpack -G DEB
$ sudo dpkg -i cuv-VERSION.deb
Building the documentation
$ cd build/debug # change to the build directory
$ make doc
Sample Code
We show two brief examples. For further inspiration, please take a look at the
test cases implemented in the src/tests directory.
Pushing and pulling of memory
C++ Code:
#include <cuv.hpp>
using namespace cuv;
int main(void){
tensor<float,host_memory_space> h(256); // reserves space in host memory
tensor<float,dev_memory_space> d(256); // reserves space in device memory
fill(h,0); // terse form
apply_0ary_functor(h,NF_FILL,0.f); // more verbose
d=h; // push to device
sequence(d); // fill device vector with a sequence
h=d; // pull to host
for(int i=0;i<h.size();i++)
{
assert(d[i] == h[i]);
}
}
Python Code:
import cuv_python as cp
import numpy as np
h = np.zeros((1,256)) # create numpy matrix
d = cp.dev_tensor_float(h) # constructs by copying numpy_array
h2 = np.zeros((1,256)).copy("F") # create numpy matrix
d2 = cp.dev_tensor_float_cm(h2) # creates dev_tensor_float_cm (column-major float) object
cp.fill(d,1) # terse form
cp.apply_nullary_functor(d,cp.nullary_functor.FILL,1) # verbose form
h = d.np # pull and convert to numpy
assert(np.sum(h) == 256)
d.dealloc() # explicitly deallocate memory (optional)
Simple Matrix operations
C++-Code
#include <cuv.hpp>
using namespace cuv;
int main(void){
tensor<float,dev_memory_space,column_major> C(2048,2048),A(2048,2048),B(2048,2048);
fill(C,0); // initialize to some defined value, not strictly necessary here
sequence(A);
sequence(B);
apply_binary_functor(A,B,BF_MULT); // elementwise multiplication
A *= B; // operators also work (elementwise)
prod(C,A,B, 'n','t'); // matrix multiplication
}
Python Code
import cuv_python as cp
import numpy as np
C = cp.dev_tensor_float_cm([2048,2048]) # column major tensor
A = cp.dev_tensor_float_cm([2048,2048])
B = cp.dev_tensor_float_cm([2048,2048])
cp.fill(C,0) # fill with some defined values, not really necessary here
cp.sequence(A)
cp.sequence(B)
cp.apply_binary_functor(B,A,cp.binary_functor.MULT) # elementwise multiplication
B *= A # operators also work (elementwise)
cp.prod(C,A,B,'n','t') # matrix multiplication
The examples can be found in the "examples/" folder under "python" and "cpp"
Generated on Mon Jul 4 2011 12:04:53 for CUV by doxygen 1.7.1