| 449 | |
| 450 | template<typename DT> |
| 451 | static void SetTensorToRandomValue(const TensorData &tensorData, DT minVal, DT maxVal, int sample) |
| 452 | { |
| 453 | if (!nvcv::TensorDataAccessStrided::IsCompatible(tensorData)) |
| 454 | throw std::runtime_error("Tensor Data is not pitch access capable."); |
| 455 | |
| 456 | auto tDataAc = nvcv::TensorDataAccessStrided::Create(tensorData); |
| 457 | |
| 458 | if (tDataAc->numSamples() <= sample) |
| 459 | throw std::runtime_error("Number of samples smaller than requested sample."); |
| 460 | |
| 461 | int inElements = (tDataAc->sampleStride() / sizeof(DT)); |
| 462 | std::vector<DT> srcVec(inElements); |
| 463 | std::default_random_engine randEng(0); |
| 464 | |
| 465 | int totalSamples; |
| 466 | if (sample < 0) |
| 467 | { |
| 468 | totalSamples = tDataAc->numSamples(); |
| 469 | sample = 0; |
| 470 | } |
| 471 | else |
| 472 | { |
| 473 | totalSamples = sample + 1; |
| 474 | } |
| 475 | std::uniform_int_distribution<DT> srcRand{minVal, maxVal}; |
| 476 | for (int i = sample; i < totalSamples; ++i) |
| 477 | { |
| 478 | std::generate(srcVec.begin(), srcVec.end(), [&]() { return srcRand(randEng); }); |
| 479 | if (cudaSuccess |
| 480 | != cudaMemcpy(tDataAc->sampleData(i), srcVec.data(), tDataAc->sampleStride(), cudaMemcpyHostToDevice)) |
| 481 | { |
| 482 | throw std::runtime_error("CudaMemcpy failed"); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | template<typename DT> |
| 490 | void SetTensorFromVector(const TensorData &tensorData, std::vector<DT> &data, int sample) |
nothing calls this directly
no test coverage detected