Giter Site home page Giter Site logo

liuying77 / cuda-nnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jirihybek/cuda-nnet

0.0 0.0 0.0 152 KB

Spiking neural network implementation using CPU and CUDA engine

Makefile 1.83% C++ 49.40% Cuda 29.67% CSS 2.44% HTML 2.42% JavaScript 14.25%

cuda-nnet's Introduction

cuda-nnet

Spiking neural network implementation using CPU and CUDA engine

Demonstration screencast:
https://www.youtube.com/watch?v=Oe1ldwEEwsI

Requirements

  • g++ compiler
  • nVidia CUDA Toolkit (nvcc compiler, cuda headers)
  • make

Compilation

make            # Build
make clean      # Clean binaries
make run        # Build and run
make run_clean  # Clean, build and run

Tested:

  • without CUDA on Macbook Pro
  • with CUDA on Ubuntu 14.04

Not tested in MS Windows environment. Usage of CygWin or another POSIX environment is recommended.

Usage

Usage: main [options] <input count> <hidden layer count> <hidden layer neurons> <output count>

  -i <count>     Count of iterations (if not specified infinite loop is started)
  -s <count>     Make output every STEP (if not specified, one output is pefromed at the end)
  -j <filename>  JS output filename
  -t <filename>  Tree output filename
  -c             Use CPU engine

Examples

# Create network with 3 inputs, 1 hidden layer with 5 neurons and 2 outputs. No dump and infinite iterations until user interrupt.
./main 3 1 5 2

# Create network same as above but do only 100 iterations.
./main -i 100 3 1 5 2

# Create network same as above do 100 iterations and dump to JSON file every 10th step.
./main -i 100 -s 10 -j dump.js 3 1 5 2

# Same as above but dump every step.
./main -i 100 -s 1 -j dump.js 3 1 5 2

Viewer

Project contains HTML viewer. To use viewer run application with following options:

main -s 1 -j dump.js

It will write network structure and state of every iteration into dump.js file.

Then open viewer.html in browser (use Google Chrome or another HTML5 compliant browser) and enter dump file name.

Then you can browse network step by step or play as animation.

Technical details

Files description

architect.cpp      # Helps with creating network structure (creates nodes and connections)
dump.cpp           # Functions for dumping network into JSON and readable tree-like format
engine.cpp         # Base class for computation engines
engine_cpu.cpp     # CPU engine
engine_gpu.cu      # CUDA GPU engine
main.cpp           # Application main file
network.cpp        # Network structure and state container

Network

Network consists of layers.

Each layer consists of inputs and neurons which are nodes.

Each node has value.

Each neuron has threshold, sum (action potential) and inputs.

Each input has weight and target node described by layer_id and node_id.

Architect

Architect class has static methods for creating network configurations.

RecurrentFeedforward network

This network model consists of input layer, multiple hidden layers and one output layer.

Connections in hidden layers are recurrent. Each neuron has chance 1/3 to connect to a random node in different layer and 2/3 chance to connect to a random node in the same layer.

Engines

Engines are created for already defined networks. They provides feed and sync methods.

Method feed sets network inputs and calculates a step.

Method sync synchronizes current network state (which is in engine memory) with network structure (which can be dumped).

CPU engine

CPU engine is demonstration of CUDA principle but computed using CPU.

Code looks ugly but one thing needs to be done. It is the flattening. Because GPU has better performance using 1D arrays.

So complex network structure needs to be flattened to one dimension which can be then effectively processed.

GPU CUDA engine

GPU engine uses the same principle as CPU engine.

GPU engine computes network in parallel:

  • Each layer is computed by block
  • Each node in layer is computed by thread

GPU engine copies network structure into memory once and then only updates inputs.

Performance observations

  • CPU and GPU engines has same performance with small networks and many iterations.
  • GPU has better performance with larger networks.

References

Possible improvements

  • Apply DRY principle (Don't Repeat Yourself) to engines
  • Architect methods for creating different ANN models
  • Extension of engines to support classical feed-forward computation with activation functions and backpropagation learning
  • OpenCL engine

cuda-nnet's People

Contributors

jirihybek avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.