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

Method RndInt8Calibrator

samples/common/sampleEngines.cpp:396–425  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

394};
395
396RndInt8Calibrator::RndInt8Calibrator(int32_t batches, std::vector<int64_t>& elemCount, std::string const& cacheFile,
397 INetworkDefinition const& network, std::ostream& err)
398 : mBatches(batches)
399 , mCurrentBatch(0)
400 , mCacheFile(cacheFile)
401 , mErr(err)
402{
403 std::ifstream tryCache(cacheFile, std::ios::binary);
404 if (tryCache.good())
405 {
406 return;
407 }
408
409 std::default_random_engine generator;
410 std::uniform_real_distribution<float> distribution(-1.0F, 1.0F);
411 auto gen = [&generator, &distribution]() { return distribution(generator); };
412
413 for (int32_t i = 0; i < network.getNbInputs(); i++)
414 {
415 auto* input = network.getInput(i);
416 std::vector<float> rnd_data(elemCount[i]);
417 std::generate_n(rnd_data.begin(), elemCount[i], gen);
418
419 void* data;
420 cudaCheck(cudaMalloc(&data, elemCount[i] * sizeof(float)), mErr);
421 cudaCheck(cudaMemcpy(data, rnd_data.data(), elemCount[i] * sizeof(float), cudaMemcpyHostToDevice), mErr);
422
423 mInputDeviceBuffers.insert(std::make_pair(input->getName(), data));
424 }
425}
426
427bool RndInt8Calibrator::getBatch(void* bindings[], char const* names[], int32_t nbBindings) noexcept
428{

Callers

nothing calls this directly

Calls 6

cudaCheckFunction · 0.85
insertMethod · 0.80
getNbInputsMethod · 0.45
getInputMethod · 0.45
dataMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected