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

Function SetTensorFromVector

tests/common/TensorDataUtils.hpp:490–524  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

488
489template<typename DT>
490void SetTensorFromVector(const TensorData &tensorData, std::vector<DT> &data, int sample)
491{
492 if (!nvcv::TensorDataAccessStrided::IsCompatible(tensorData))
493 throw std::runtime_error("Tensor Data is not pitch access capable.");
494
495 auto tDataAc = nvcv::TensorDataAccessStrided::Create(tensorData);
496
497 if ((int64_t)(data.size() * sizeof(DT)) != tDataAc->sampleStride())
498 throw std::runtime_error("Data vector is incorrect size.");
499
500 if (tDataAc->numSamples() <= sample)
501 throw std::runtime_error("Number of samples smaller than requested sample.");
502
503 if (sample < 0)
504 {
505 for (int i = 0; i < tDataAc->numSamples(); ++i)
506 {
507 if (cudaSuccess
508 != cudaMemcpy(tDataAc->sampleData(i), data.data(), tDataAc->sampleStride(), cudaMemcpyHostToDevice))
509 {
510 throw std::runtime_error("CudaMemcpy failed");
511 }
512 }
513 }
514 else
515 {
516 if (cudaSuccess
517 != cudaMemcpy(tDataAc->sampleData(sample), data.data(), tDataAc->sampleStride(), cudaMemcpyHostToDevice))
518 {
519 throw std::runtime_error("CudaMemcpy failed");
520 }
521 }
522
523 return;
524}
525
526template<typename DT>
527void GetVectorFromTensor(const TensorData &tensorData, int sample, std::vector<DT> &outData)

Callers

nothing calls this directly

Calls 5

sampleStrideMethod · 0.80
sizeMethod · 0.45
numSamplesMethod · 0.45
sampleDataMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected