better rt inference
This commit is contained in:
+2
-1
@@ -32,6 +32,7 @@ public:
|
|||||||
Do inferece
|
Do inferece
|
||||||
*/
|
*/
|
||||||
dnnType* infer(dataDim_t &dim, dnnType* data);
|
dnnType* infer(dataDim_t &dim, dnnType* data);
|
||||||
|
void enqueue();
|
||||||
|
|
||||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Layer *l);
|
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Layer *l);
|
||||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Conv2d *l);
|
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Conv2d *l);
|
||||||
@@ -62,4 +63,4 @@ template<typename T> T readBUF(const char*& buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif //NETWORKRT_H
|
#endif //NETWORKRT_H
|
||||||
|
|||||||
@@ -139,6 +139,10 @@ dnnType* NetworkRT::infer(dataDim_t &dim, dnnType* data) {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetworkRT::enqueue() {
|
||||||
|
contextRT->enqueue(1, buffersRT, stream, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
ILayer* NetworkRT::convert_layer(ITensor *input, Layer *l) {
|
ILayer* NetworkRT::convert_layer(ITensor *input, Layer *l) {
|
||||||
|
|
||||||
layerType_t type = l->getLayerType();
|
layerType_t type = l->getLayerType();
|
||||||
|
|||||||
@@ -1,24 +1,33 @@
|
|||||||
#include<iostream>
|
#include<iostream>
|
||||||
#include "tkdnn.h"
|
#include "tkdnn.h"
|
||||||
|
#include <stdlib.h> /* srand, rand */
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
if(argc < 2 || !fileExist(argv[1]))
|
if(argc < 2 || !fileExist(argv[1]))
|
||||||
FatalError("unable to read serialRT file");
|
FatalError("unable to read serialRT file");
|
||||||
|
|
||||||
|
//always same test
|
||||||
|
srand (0);
|
||||||
|
|
||||||
//convert network to tensorRT
|
//convert network to tensorRT
|
||||||
tkDNN::NetworkRT netRT(NULL, argv[1]);
|
tkDNN::NetworkRT netRT(NULL, argv[1]);
|
||||||
|
|
||||||
tkDNN::dataDim_t dim = netRT.input_dim;
|
dnnType *input = new float[netRT.input_dim.tot()];
|
||||||
dnnType *data;
|
dnnType *output = new float[netRT.input_dim.tot()];
|
||||||
checkCuda(cudaMalloc(&data, dim.tot()*sizeof(dnnType)));
|
|
||||||
|
|
||||||
printCenteredTitle(" TENSORRT inference ", '=', 30); {
|
printCenteredTitle(" TENSORRT inference ", '=', 30);
|
||||||
dim.print();
|
for(int i=0; i<100; i++) {
|
||||||
|
for(int j=0; j<netRT.input_dim.tot(); j++)
|
||||||
|
input[j] = ((float) rand() / (RAND_MAX));
|
||||||
TIMER_START
|
TIMER_START
|
||||||
data = netRT.infer(dim, data);
|
checkCuda( cudaMemcpyAsync(netRT.buffersRT[netRT.buf_input_idx], input,
|
||||||
|
netRT.input_dim.tot()*sizeof(float), cudaMemcpyHostToDevice, netRT.stream));
|
||||||
|
netRT.enqueue();
|
||||||
|
checkCuda( cudaMemcpyAsync(output, netRT.buffersRT[netRT.buf_output_idx],
|
||||||
|
netRT.output_dim.tot()*sizeof(float), cudaMemcpyDeviceToHost, netRT.stream));
|
||||||
|
cudaStreamSynchronize(netRT.stream);
|
||||||
TIMER_STOP
|
TIMER_STOP
|
||||||
dim.print();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user