From bed0b57fade22636223b47687290de89544c5044 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Tue, 1 Aug 2017 18:08:56 +0200 Subject: [PATCH] mnist tensor --- CMakeLists.txt | 7 ++- tests/mnist/{test.cpp => test_mnist.cpp} | 0 tests/mnist/test_mnistRT.cpp | 66 ++++++++++++++++++++++++ tests/test/{test.cpp => test_simple.cpp} | 0 4 files changed, 71 insertions(+), 2 deletions(-) rename tests/mnist/{test.cpp => test_mnist.cpp} (100%) create mode 100644 tests/mnist/test_mnistRT.cpp rename tests/test/{test.cpp => test_simple.cpp} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19ab58e..0a30260 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,11 +18,14 @@ add_library(tkDNN SHARED src/Layer.cpp src/LayerWgs.cpp src/Route.cpp src/Reorg.cpp src/Region.cpp src/Network.cpp src/utils.cpp) target_link_libraries(tkDNN kernels ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} -lcudnn -lnvinfer) -add_executable(test_simple tests/test/test.cpp) +add_executable(test_simple tests/test/test_simple.cpp) target_link_libraries(test_simple tkDNN) -add_executable(test_mnist tests/mnist/test.cpp) +add_executable(test_mnist tests/mnist/test_mnist.cpp) target_link_libraries(test_mnist tkDNN) +add_executable(test_mnistRT tests/mnist/test_mnistRT.cpp) +target_link_libraries(test_mnistRT tkDNN) + add_executable(test_yolo tests/yolo/yolo.cpp) target_link_libraries(test_yolo tkDNN) \ No newline at end of file diff --git a/tests/mnist/test.cpp b/tests/mnist/test_mnist.cpp similarity index 100% rename from tests/mnist/test.cpp rename to tests/mnist/test_mnist.cpp diff --git a/tests/mnist/test_mnistRT.cpp b/tests/mnist/test_mnistRT.cpp new file mode 100644 index 0000000..8ce27ab --- /dev/null +++ b/tests/mnist/test_mnistRT.cpp @@ -0,0 +1,66 @@ +#include +#include "tkdnn.h" +#include "NvInfer.h" + +const char *input_bin = "../tests/mnist/input.bin"; +const char *c0_bin = "../tests/mnist/layers/c0.bin"; +const char *c1_bin = "../tests/mnist/layers/c1.bin"; +const char *d2_bin = "../tests/mnist/layers/d2.bin"; +const char *d3_bin = "../tests/mnist/layers/d3.bin"; +const char *output_bin = "../tests/mnist/output.bin"; + +// Logger for info/warning/errors +class Logger : public nvinfer1::ILogger +{ + void log(Severity severity, const char* msg) override + { + // suppress info-level messages + if (severity != Severity::kINFO) + std::cout << msg << std::endl; + } +} gLogger; + +int main() { + + std::cout<<"\n==== CUDNN ====\n"; + // Network layout + tkDNN::Network net; + tkDNN::dataDim_t dim(1, 1, 28, 28, 1); + tkDNN::Layer *l; + l = new tkDNN::Conv2d (&net, dim, 20, 5, 5, 1, 1, 0, 0, c0_bin); + l = new tkDNN::Pooling (&net, l->output_dim, 2, 2, 2, 2, tkDNN::POOLING_MAX); + l = new tkDNN::Conv2d (&net, l->output_dim, 50, 5, 5, 1, 1, 0, 0, c1_bin); + l = new tkDNN::Pooling (&net, l->output_dim, 2, 2, 2, 2, tkDNN::POOLING_MAX); + l = new tkDNN::Dense (&net, l->output_dim, 500, d2_bin); + l = new tkDNN::Activation (&net, l->output_dim, CUDNN_ACTIVATION_RELU); + l = new tkDNN::Dense (&net, l->output_dim, 10, d3_bin); + l = new tkDNN::Softmax (&net, l->output_dim); + + // Load input + value_type *data; + value_type *input_h; + readBinaryFile(input_bin, dim.tot(), &input_h, &data); + + dim.print(); //print initial dimension + + TIMER_START + // Inference + data = net.infer(dim, data); + TIMER_STOP + dim.print(); + + // Print real test + std::cout<<"\n==== CHECK CUDNN RESULT ====\n"; + value_type *out; + value_type *out_h; + readBinaryFile(output_bin, dim.tot(), &out_h, &out); + std::cout<<"Diff: "<createNetwork(); + + return 0; +} diff --git a/tests/test/test.cpp b/tests/test/test_simple.cpp similarity index 100% rename from tests/test/test.cpp rename to tests/test/test_simple.cpp