Skip to content

Commit

Permalink
add scripts, plugin code is working
Browse files Browse the repository at this point in the history
  • Loading branch information
mavenlin committed Jun 25, 2013
1 parent 73e9ebc commit 94931bd
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Kernel/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MODELNAME := kernel
MODELNAME := libkernel

INCLUDES := -I$(PYTHON_INCLUDE_PATH) -I$(NUMPY_INCLUDE_PATH) -I./include/data -I./include/layers -I./include/matrix -I./include/conv -I./include/nvmatrix -I./include/convnet -I$(INTEL_MKL_PATH)/include
LIB := -lpthread -L$(CUDA_INSTALL_PATH)/lib64 -L$(INTEL_MKL_PATH)/lib/intel64 -lmkl_rt -ldl
Expand Down
2 changes: 1 addition & 1 deletion Kernel/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ export NUMPY_INCLUDE_PATH=/home/svu/a0089298/usr/local/lib/python2.7/site-packag

export INTEL_MKL_PATH=/home/svu/a0089298/intel/mkl

make $*
make -j 4 $*

7 changes: 7 additions & 0 deletions Kernel/src/convnet/plugin.cu
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "plugin.cuh"
#include <dirent.h>
#include <dlfcn.h>
#include <iostream>

using namespace std;

std::map<string, layerConFunc> layers;
std::map<string, neuronConFunc> neurons;
Expand All @@ -46,10 +49,14 @@ void loadPlugins(){
cout<<"loading plugin "<<files->d_name<<endl;
string plugin = "Plugins/" + string(files->d_name);
void * handle = dlopen(plugin.c_str(), RTLD_NOW);
if(dlerror())
cout<<dlerror()<<endl;
// TODO
// Add error check code in dlsym
// get layer constructors from current plugin
layerConstructorP layerCon = (layerConstructorP)dlsym(handle, "layerConstructor");
if(dlerror())
cout<<dlerror()<<endl;
std::map<string, layerConFunc> layerConMap = layerCon();
layers.insert(layerConMap.begin(), layerConMap.end());
// get neuron constructors from current plugin
Expand Down
4 changes: 2 additions & 2 deletions Plugins/Makefile → PluginsSrc/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
MODELNAME := extralayers

INCLUDES := -I$(PYTHON_INCLUDE_PATH) -I$(NUMPY_INCLUDE_PATH) -I../Kernel/include/data -I../Kernel/include/layers -I../Kernel/include/matrix -I../Kernel/include/conv -I../Kernel/include/nvmatrix -I../Kernel/include/convnet -I$(INTEL_MKL_PATH)/include
INCLUDES := -I$(PYTHON_INCLUDE_PATH) -I$(NUMPY_INCLUDE_PATH) -I../Kernel/include/data -I../Kernel/include/layers -I../Kernel/include/matrix -I../Kernel/include/conv -I../Kernel/include/nvmatrix -I../Kernel/include/convnet -I./include -I$(INTEL_MKL_PATH)/include
LIB := -lpthread -L$(CUDA_INSTALL_PATH)/lib64 -L$(INTEL_MKL_PATH)/lib/intel64 -lmkl_rt -ldl

USECUBLAS := 1
USE_MKL := 1

PYTHON_VERSION=$(shell $(PYTHON_BIN_PATH)/python -V 2>&1 | cut -d ' ' -f 2 | cut -d '.' -f 1,2)
LIB += -L$(PYTHON_LIB_PATH) -lpython$(PYTHON_VERSION) -L../Kernel/bin/linux/release -l_ConvNet
LIB += -L$(PYTHON_LIB_PATH) -lpython$(PYTHON_VERSION) -L../Kernel/bin/linux/release -lkernel

GENCODE_ARCH := -gencode=arch=compute_20,code=\"sm_20,compute_20\"
COMMONFLAGS := -DNUMPY_INTERFACE -DMODELNAME=$(MODELNAME) -DINITNAME=init$(MODELNAME)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions Plugins/src/extralayers.cu → PluginsSrc/src/extralayers.cu
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ GroupSparsityInLabelCostLayer::GroupSparsityInLabelCostLayer(ConvNet* convNet, P


// Define a function that creates a new Labelgroupsparsity layer and return the pointer
GroupSparsityInLabelCostLayer* CreateGroupSparsityInLabelCostLayer(ConvNet* convNet, PyObject* paramsDict){
Layer* CreateGroupSparsityInLabelCostLayer(ConvNet* convNet, PyObject* paramsDict){
return new GroupSparsityInLabelCostLayer(convNet, paramsDict);
}

Expand All @@ -55,15 +55,15 @@ GroupSparsityInLabelCostLayer* CreateGroupSparsityInLabelCostLayer(ConvNet* conv
// The following two functions are exported from the shared object.
// All constructors of the layers or neurons defined in this shared library should be returned from this function.
// Explicitly export this two functions which is used as the standard interface of the plugin.
__attribute__((visibility("default")))
extern "C" __attribute__((visibility("default")))
std::map<string, layerConFunc> layerConstructor(){
std::cout<<"Getting the layer constructors inside this shared library"<<std::endl;
std::map<string, layerConFunc> ret;
ret["LabelGroupSparsityCostLayer"] = &CreateGroupSparsityInLabelCostLayer;
return ret;
}

__attribute__((visibility("default")))
extern "C" __attribute__((visibility("default")))
std::map<string, neuronConFunc> neuronConstructor(){
return std::map<string, neuronConFunc>();
}
6 changes: 3 additions & 3 deletions Plugins/src/extrautils.cu → PluginsSrc/src/extrautils.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

void sparse_histogram(float * input, int num, device_vector<float>& histogram_values, device_vector<int>& histogram_counts)
{
typedef typename float ValueType; // input value type
typedef typename int IndexType; // histogram index type
typedef float ValueType; // input value type
typedef int IndexType; // histogram index type

// copy input data
thrust::device_ptr<float> d_ptr(input);
Expand Down Expand Up @@ -110,4 +110,4 @@ void CalculateGradient(NVMatrix& acts, NVMatrix& labels, NVMatrix& sqrts, thrust
dim3 blocks(gridxdim, gridydim); // The dimension of the grid
dim3 threads(32, 16); // The dimension of the block, 32 x 16 = 512, which is the thread number available inside a block for compute compatibility<2.0.
kCalculateGradient<16,32><<<blocks, threads>>>(acts.getDevData(), labels.getDevData(), sqrts.getDevData(), thrust::raw_pointer_cast(values.data()), thrust::raw_pointer_cast(counts.data()), counts.size(), channels, imagePixels, numCases, target.getDevData());
}
}
13 changes: 13 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cd Kernel
./build.sh
cd ..

cd PluginsSrc
./build.sh
cd ..

cp Kernel/bin/linux/release/libkernel.so ./
rm -rf Plugins
mkdir Plugins
cp PluginsSrc/bin/linux/release/* ./Plugins/

8 changes: 8 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cd Kernel
make clean
cd ..
cd PluginsSrc
make clean
cd ..
rm libkernel.so
rm -rf Plugins
2 changes: 2 additions & 0 deletions setupldpath.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export INTEL_MKL_PATH=/home/svu/a0089298/intel/mkl
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$INTEL_MKL_PATH/lib/intel64:$HOME/usr/local/lib:$HOME/lib:./

0 comments on commit 94931bd

Please sign in to comment.