MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / infer

Method infer

samples/sampleIOFormats/sampleIOFormats.cpp:426–460  ·  view source on GitHub ↗

\brief Runs the TensorRT inference engine for this sample \details This function is the main execution function of the sample. It allocates the buffer, sets inputs, executes the engine, and verifies the output.

Source from the content-addressed store, hash-verified

424//! the buffer, sets inputs, executes the engine, and verifies the output.
425//!
426bool SampleIOFormats::infer(SampleBuffer& inputBuf, SampleBuffer& outputBuf)
427{
428 auto const devInput = mallocCudaMem<uint8_t>(inputBuf.getBufferSize());
429 auto devOutput = mallocCudaMem<uint8_t>(outputBuf.getBufferSize());
430
431 CHECK(cudaMemcpy(devInput.get(), inputBuf.buffer, inputBuf.getBufferSize(), cudaMemcpyHostToDevice));
432
433 auto context = SampleUniquePtr<nvinfer1::IExecutionContext>(mEngine->createExecutionContext());
434 if (!context)
435 {
436 return false;
437 }
438
439 // Create CUDA stream for the execution of this inference.
440 cudaStream_t stream;
441 CHECK(cudaStreamCreate(&stream));
442
443 void* bindings[2] = {devInput.get(), devOutput.get()};
444
445 // Asynchronously enqueue the inference work
446 if (!context->enqueueV2(bindings, stream, nullptr))
447 {
448 return false;
449 }
450
451 // Wait for the work in the stream to complete
452 CHECK(cudaStreamSynchronize(stream));
453
454 // Release stream
455 CHECK(cudaStreamDestroy(stream));
456
457 CHECK(cudaMemcpy(outputBuf.buffer, devOutput.get(), outputBuf.getBufferSize(), cudaMemcpyDeviceToHost));
458
459 return true;
460}
461
462//!
463//! \brief Reads the digit map from file

Callers 2

processFunction · 0.45
runFP32ReferenceFunction · 0.45

Calls 4

enqueueV2Method · 0.80
getBufferSizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected