MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / SetImageTensorFromByteVectorPlanar

Function SetImageTensorFromByteVectorPlanar

tests/common/TensorDataUtils.cpp:322–364  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

320}
321
322static void SetImageTensorFromByteVectorPlanar(const TensorData &tensorData, std::vector<nvcv::Byte> &data, int sample)
323{
324 Optional<TensorDataAccessStridedImagePlanar> tDataAc = nvcv::TensorDataAccessStridedImagePlanar::Create(tensorData);
325
326 if (!tDataAc)
327 throw std::runtime_error("Tensor Data not compatible with planar image access.");
328
329 if (tDataAc->numSamples() <= sample)
330 throw std::runtime_error("Number of samples smaller than requested sample.");
331
332 if ((int64_t)data.size()
333 != tDataAc->numCols() * tDataAc->numRows() * (tDataAc->dtype().bitsPerPixel() / 8) * tDataAc->numChannels())
334 throw std::runtime_error("Data vector is incorrect size, size must be W*H*bytesPerPixel.");
335
336 int bytesPerC = (tDataAc->dtype().bitsPerPixel() / 8);
337
338 auto copyToGpu = [&](int j)
339 {
340 Byte *basePtr = tDataAc->sampleData(j);
341
342 for (int i = 0; i < tDataAc->numChannels(); ++i)
343 {
344 Byte *srcPtr = data.data() + (i * (tDataAc->numCols() * tDataAc->numRows() * bytesPerC));
345 size_t srcPitch = tDataAc->numCols() * bytesPerC;
346 size_t srcWidthBytes = tDataAc->numCols() * bytesPerC;
347 if (cudaSuccess
348 != cudaMemcpy2D(basePtr, tDataAc->rowStride(), srcPtr, srcPitch, srcWidthBytes, tDataAc->numRows(),
349 cudaMemcpyHostToDevice))
350 {
351 throw std::runtime_error("CudaMemcpy failed for channel plane copy from host to device.");
352 }
353 basePtr += tDataAc->planeStride();
354 }
355 };
356
357 if (sample < 0)
358 for (auto i = 0; i < tDataAc->numSamples(); ++i)
359 {
360 copyToGpu(i);
361 }
362 else
363 copyToGpu(sample);
364}
365
366void SetImageTensorFromByteVector(const TensorData &tensorData, std::vector<nvcv::Byte> &data, int sample)
367{

Callers 1

Calls 11

bitsPerPixelMethod · 0.80
numSamplesMethod · 0.45
sizeMethod · 0.45
numColsMethod · 0.45
numRowsMethod · 0.45
dtypeMethod · 0.45
numChannelsMethod · 0.45
sampleDataMethod · 0.45
dataMethod · 0.45
rowStrideMethod · 0.45
planeStrideMethod · 0.45

Tested by

no test coverage detected