| 357 | |
| 358 | template<typename DT> |
| 359 | void 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 | |
| 399 | template<typename DT> |
| 400 | static void SetTensorToRandomValueFloat(const TensorData &tensorData, DT minVal, DT maxVal, int sample) |
nothing calls this directly
no test coverage detected