This commit is contained in:
Francesco Gatti
2017-08-04 16:16:03 +00:00
parent b20a2e2902
commit 34198a4e8d
6 changed files with 55 additions and 29 deletions
+2 -4
View File
@@ -1,5 +1,4 @@
#include <iostream>
#include "NvInfer.h"
#include "tkdnn.h"
#include "Network.h"
@@ -12,10 +11,9 @@ Network::Network(dataDim_t input_dim) {
float tk_ver = float(tkDNN::getVersion())/1000;
float cu_ver = float(cudnnGetVersion())/1000;
float rt_ver = float(NV_TENSORRT_MAJOR) + float(NV_TENSORRT_MINOR)/10 + float(NV_TENSORRT_PATCH)/100;
std::cout<<"New NETWORK (tkDNN v"<<tk_ver
<<", CUDNN v"<<cu_ver<<", TensorRT v"<<rt_ver<<")\n";
<<", CUDNN v"<<cu_ver<<")\n";
dataType = CUDNN_DATA_FLOAT;
tensorFormat = CUDNN_TENSOR_NCHW;
@@ -57,4 +55,4 @@ dataDim_t Network::getOutputDim() {
return layers[num_layers-1]->output_dim;
}
}
}
+10 -7
View File
@@ -10,12 +10,10 @@ using namespace nvinfer1;
#include "pluginsRT/RegionRT.cpp"
// Logger for info/warning/errors
class Logger : public ILogger
{
void log(Severity severity, const char* msg) override
{
std::cout <<"TENSORRT: "<< msg << std::endl;
}
class Logger : public ILogger {
void log(Severity severity, const char* msg) override {
std::cout <<"TENSORRT LOG: "<< msg << std::endl;
}
} loggerRT;
namespace tkDNN {
@@ -24,6 +22,11 @@ std::map<Layer*, nvinfer1::ITensor*>tensors;
NetworkRT::NetworkRT(Network *net) {
float rt_ver = float(NV_TENSORRT_MAJOR) +
float(NV_TENSORRT_MINOR)/10 +
float(NV_TENSORRT_PATCH)/100;
std::cout<<"New NetworkRT (TensorRT v"<<rt_ver<<")\n";
builderRT = createInferBuilder(loggerRT);
networkRT = builderRT->createNetwork();
dtRT = DataType::kFLOAT;
@@ -250,4 +253,4 @@ ITensor* NetworkRT::convert_layer(ITensor *input, Region *l) {
return lRT->getOutput(0);
}
}
}
+15 -8
View File
@@ -23,9 +23,7 @@ void readBinaryFile(const char* fname, int size, value_type** data_h, value_type
}
checkCuda( cudaMalloc(data_d, size_b) );
checkCuda( cudaMemcpy(*data_d, *data_h,
size_b,
cudaMemcpyHostToDevice) );
checkCuda( cudaMemcpy(*data_d, *data_h, size_b, cudaMemcpyHostToDevice) );
}
void printDeviceVector(int size, value_type* vec_d, bool device)
@@ -39,8 +37,7 @@ void printDeviceVector(int size, value_type* vec_d, bool device)
vec = vec_d;
}
for (int i = 0; i < size; i++)
{
for (int i = 0; i < size; i++) {
std::cout << vec[i] << " ";
}
std::cout << std::endl;
@@ -52,6 +49,7 @@ void printDeviceVector(int size, value_type* vec_d, bool device)
int checkResult(int size, value_type *data_d, value_type *correct_d, bool device) {
value_type *data_h, *correct_h;
const float eps = 0.0001f;
if(device) {
data_h = new value_type[size];
@@ -67,10 +65,12 @@ int checkResult(int size, value_type *data_d, value_type *correct_d, bool device
int diffs = 0;
for(int i=0; i<size; i++) {
if(fabs(data_h[i] - correct_h[i]) > 0.0001) {
if(fabs(data_h[i] - correct_h[i]) > eps) {
diffs += 1;
if(diffs == 1)
std::cout<<"\n";
if(diffs < 10)
printf("%d: %f %f\n", i, data_h[i], correct_h[i]);
std::cout<<" | [ "<<i<<" ]: "<<data_h[i]<<" "<<correct_h[i]<<"\n";
}
}
@@ -79,6 +79,13 @@ int checkResult(int size, value_type *data_d, value_type *correct_d, bool device
delete [] correct_h;
}
std::cout<<" | ";
if(diffs == 0)
std::cout<<COL_GREENB<<"OK";
else
std::cout<<COL_REDB<<"Wrongs: "<<diffs;
std::cout<<COL_END<<" ~"<<eps<<"\n";
return diffs;
}
@@ -108,4 +115,4 @@ void matrixMulAdd( cublasHandle_t handle, value_type* srcData, value_type* dstD
value_type alpha = mul;
checkERROR( cublasSaxpy(handle, dim, &alpha, srcData, 1, dstData, 1));
}
}