| 320 | } |
| 321 | |
| 322 | static 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 | |
| 366 | void SetImageTensorFromByteVector(const TensorData &tensorData, std::vector<nvcv::Byte> &data, int sample) |
| 367 | { |
no test coverage detected