1 command network inference
This commit is contained in:
@@ -5,16 +5,31 @@
|
|||||||
|
|
||||||
namespace tkDNN {
|
namespace tkDNN {
|
||||||
|
|
||||||
|
struct dataDim_t;
|
||||||
|
class Layer;
|
||||||
|
const int MAX_LAYERS = 256;
|
||||||
|
|
||||||
class Network {
|
class Network {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Network();
|
Network();
|
||||||
virtual ~Network();
|
virtual ~Network();
|
||||||
|
|
||||||
|
/**
|
||||||
|
Do inferece for every added layer
|
||||||
|
*/
|
||||||
|
value_type* infer(dataDim_t &dim, value_type* data);
|
||||||
|
|
||||||
|
bool addLayer(Layer *l);
|
||||||
|
|
||||||
cudnnDataType_t dataType;
|
cudnnDataType_t dataType;
|
||||||
cudnnTensorFormat_t tensorFormat;
|
cudnnTensorFormat_t tensorFormat;
|
||||||
cudnnHandle_t cudnnHandle;
|
cudnnHandle_t cudnnHandle;
|
||||||
cublasHandle_t cublasHandle;
|
cublasHandle_t cublasHandle;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Layer* layers[MAX_LAYERS]; //contains layers of the net
|
||||||
|
int num_layers; //current number of layers
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ Layer::Layer(Network *net, dataDim_t in_dim) {
|
|||||||
|
|
||||||
checkCUDNN( cudnnCreateTensorDescriptor(&srcTensorDesc) );
|
checkCUDNN( cudnnCreateTensorDescriptor(&srcTensorDesc) );
|
||||||
checkCUDNN( cudnnCreateTensorDescriptor(&dstTensorDesc) );
|
checkCUDNN( cudnnCreateTensorDescriptor(&dstTensorDesc) );
|
||||||
|
|
||||||
|
if(!net->addLayer(this))
|
||||||
|
FatalError("Net reached max number of layers");
|
||||||
}
|
}
|
||||||
|
|
||||||
Layer::~Layer() {
|
Layer::~Layer() {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "Network.h"
|
#include "Network.h"
|
||||||
|
#include "Layer.h"
|
||||||
|
|
||||||
namespace tkDNN {
|
namespace tkDNN {
|
||||||
|
|
||||||
@@ -12,6 +13,8 @@ Network::Network() {
|
|||||||
|
|
||||||
checkCUDNN( cudnnCreate(&cudnnHandle) );
|
checkCUDNN( cudnnCreate(&cudnnHandle) );
|
||||||
checkERROR( cublasCreate(&cublasHandle) );
|
checkERROR( cublasCreate(&cublasHandle) );
|
||||||
|
|
||||||
|
num_layers = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Network::~Network() {
|
Network::~Network() {
|
||||||
@@ -20,4 +23,21 @@ Network::~Network() {
|
|||||||
checkERROR( cublasDestroy(cublasHandle) );
|
checkERROR( cublasDestroy(cublasHandle) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value_type* Network::infer(dataDim_t &dim, value_type* data) {
|
||||||
|
|
||||||
|
//do infer for every layer
|
||||||
|
for(int i=0; i<num_layers; i++)
|
||||||
|
data = layers[i]->infer(dim, data);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Network::addLayer(Layer *l) {
|
||||||
|
if(num_layers == MAX_LAYERS)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
layers[num_layers++] = l;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+5
-1
@@ -29,11 +29,15 @@ int main() {
|
|||||||
TIMER_START
|
TIMER_START
|
||||||
|
|
||||||
// Inference
|
// Inference
|
||||||
|
data = net.infer(dim, data); dim.print();
|
||||||
|
|
||||||
|
/*
|
||||||
|
//old Inference method
|
||||||
data = c0.infer(dim, data); dim.print();
|
data = c0.infer(dim, data); dim.print();
|
||||||
data = a0.infer(dim, data); dim.print();
|
data = a0.infer(dim, data); dim.print();
|
||||||
data = c1.infer(dim, data); dim.print();
|
data = c1.infer(dim, data); dim.print();
|
||||||
data = a1.infer(dim, data); dim.print();
|
data = a1.infer(dim, data); dim.print();
|
||||||
|
*/
|
||||||
TIMER_STOP
|
TIMER_STOP
|
||||||
// Print result
|
// Print result
|
||||||
printDeviceVector(dim.tot(), data);
|
printDeviceVector(dim.tot(), data);
|
||||||
|
|||||||
Reference in New Issue
Block a user