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

Method addBinding

samples/common/sampleInference.cpp:1376–1440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1374}
1375
1376void Bindings::addBinding(TensorInfo const& tensorInfo, std::string const& fileName /*= ""*/)
1377{
1378 auto const b = tensorInfo.bindingIndex;
1379 while (mBindings.size() <= static_cast<size_t>(b))
1380 {
1381 mBindings.emplace_back();
1382 mDevicePointers.emplace_back();
1383 }
1384 mNames[tensorInfo.name] = b;
1385 mBindings[b].isInput = tensorInfo.isInput;
1386 mBindings[b].volume = tensorInfo.vol;
1387 mBindings[b].dataType = tensorInfo.dataType;
1388 if (tensorInfo.isDynamic)
1389 {
1390 ASSERT(!tensorInfo.isInput); // Only output shape can be possibly unknown because of DDS.
1391 if (mBindings[b].outputAllocator == nullptr)
1392 {
1393 if (mUseManaged)
1394 {
1395 mBindings[b].outputAllocator.reset(new OutputAllocator(new UnifiedMirroredBuffer));
1396 }
1397 else
1398 {
1399 mBindings[b].outputAllocator.reset(new OutputAllocator(new DiscreteMirroredBuffer));
1400 }
1401 }
1402 }
1403 else
1404 {
1405 if (mBindings[b].buffer == nullptr)
1406 {
1407 if (mUseManaged)
1408 {
1409 mBindings[b].buffer.reset(new UnifiedMirroredBuffer);
1410 }
1411 else
1412 {
1413 mBindings[b].buffer.reset(new DiscreteMirroredBuffer);
1414 }
1415 }
1416 // Some memory allocators return nullptr when allocating zero bytes, but TensorRT requires a non-null ptr
1417 // even for empty tensors, so allocate a dummy byte.
1418 if (tensorInfo.vol == 0)
1419 {
1420 mBindings[b].buffer->allocate(1);
1421 }
1422 else
1423 {
1424 mBindings[b].buffer->allocate(
1425 static_cast<size_t>(tensorInfo.vol) * static_cast<size_t>(dataTypeSize(tensorInfo.dataType)));
1426 }
1427 mDevicePointers[b] = mBindings[b].buffer->getDeviceBuffer();
1428 }
1429 if (tensorInfo.isInput)
1430 {
1431 if (fileName.empty())
1432 {
1433 fill(b);

Callers 1

fillOneBindingMethod · 0.80

Calls 6

dataTypeSizeFunction · 0.85
sizeMethod · 0.45
resetMethod · 0.45
allocateMethod · 0.45
getDeviceBufferMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected