\brief Preprocess inputs and allocate host/device input buffers
| 414 | //! \brief Preprocess inputs and allocate host/device input buffers |
| 415 | //! |
| 416 | bool SampleINT8API::prepareInput(const samplesCommon::BufferManager& buffers) |
| 417 | { |
| 418 | if (samplesCommon::toLower(samplesCommon::getFileType(mParams.imageFileName)).compare("ppm") != 0) |
| 419 | { |
| 420 | sample::gLogError << "Wrong format: " << mParams.imageFileName << " is not a ppm file." << std::endl; |
| 421 | return false; |
| 422 | } |
| 423 | |
| 424 | int channels = mParams.mPreproc.inputDims.at(1); |
| 425 | int height = mParams.mPreproc.inputDims.at(2); |
| 426 | int width = mParams.mPreproc.inputDims.at(3); |
| 427 | int max{0}; |
| 428 | std::string magic; |
| 429 | |
| 430 | std::vector<uint8_t> fileData(channels * height * width); |
| 431 | |
| 432 | std::ifstream infile(mParams.imageFileName, std::ifstream::binary); |
| 433 | ASSERT(infile.is_open() && "Attempting to read from a file that is not open."); |
| 434 | infile >> magic >> width >> height >> max; |
| 435 | infile.seekg(1, infile.cur); |
| 436 | infile.read(reinterpret_cast<char*>(fileData.data()), width * height * channels); |
| 437 | |
| 438 | uint8_t* hostInputBuffer = static_cast<uint8_t*>(buffers.getHostBuffer(mInOut["input"])); |
| 439 | |
| 440 | // Convert HWC to CHW and Normalize |
| 441 | for (int c = 0; c < channels; ++c) |
| 442 | { |
| 443 | for (int h = 0; h < height; ++h) |
| 444 | { |
| 445 | for (int w = 0; w < width; ++w) |
| 446 | { |
| 447 | int dstIdx = c * height * width + h * width + w; |
| 448 | int srcIdx = h * width * channels + w * channels + c; |
| 449 | hostInputBuffer[dstIdx] = fileData[srcIdx]; |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | return true; |
| 454 | } |
| 455 | |
| 456 | //! |
| 457 | //! \brief Verifies that the output is correct and prints it |
nothing calls this directly
no test coverage detected