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

Function SetTensorTo

tests/common/TensorDataUtils.hpp:359–397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

357
358template<typename DT>
359void SetTensorTo(const TensorData &tensorData, DT data, int sample)
360{
361 if (!nvcv::TensorDataAccessStrided::IsCompatible(tensorData))
362 throw std::runtime_error("Tensor Data is not pitch access capable.");
363
364 auto tDataAc = nvcv::TensorDataAccessStrided::Create(tensorData);
365
366 if (tDataAc->numSamples() <= sample)
367 throw std::runtime_error("Number of samples smaller than requested sample.");
368
369 int inElements = (tDataAc->sampleStride() / sizeof(DT));
370 std::vector<DT> srcVec(inElements, data);
371
372 int totalSamples;
373 if (sample < 0)
374 {
375 totalSamples = tDataAc->numSamples();
376 sample = 0;
377 }
378 else
379 {
380 totalSamples = sample + 1;
381 }
382
383 for (int i = sample; i < totalSamples; ++i)
384 {
385 auto *outSamplePtr = tDataAc->sampleData(i);
386 size_t size = tDataAc->sampleStride();
387 if (auto err = cudaMemcpy(outSamplePtr, srcVec.data(), size, cudaMemcpyHostToDevice))
388 {
389 char msg[1024] = {};
390 snprintf(msg, sizeof(msg), "CudaMemcpy failed with %s (%i): %s", cudaGetErrorName(err), err,
391 cudaGetErrorString(err));
392 throw std::runtime_error(msg);
393 }
394 }
395
396 return;
397}
398
399template<typename DT>
400static void SetTensorToRandomValueFloat(const TensorData &tensorData, DT minVal, DT maxVal, int sample)

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected