| 1374 | } |
| 1375 | |
| 1376 | void 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); |
no test coverage detected