| 60 | } |
| 61 | |
| 62 | void PriorBox::setupDeviceMemory() noexcept |
| 63 | { |
| 64 | auto copyToDevice = [](void const* hostData, int32_t count) -> Weights { |
| 65 | PLUGIN_VALIDATE(count >= 0); |
| 66 | void* deviceData = nullptr; |
| 67 | PLUGIN_CUASSERT(cudaMalloc(&deviceData, count * sizeof(float))); |
| 68 | PLUGIN_CUASSERT(cudaMemcpy(deviceData, hostData, count * sizeof(float), cudaMemcpyHostToDevice)); |
| 69 | return Weights{DataType::kFLOAT, deviceData, static_cast<int64_t>(count)}; |
| 70 | }; |
| 71 | |
| 72 | // minSize is required and needs to be positive. |
| 73 | PLUGIN_VALIDATE(mParam.numMinSize > 0); |
| 74 | PLUGIN_VALIDATE(mParam.minSize != nullptr); |
| 75 | for (int32_t i = 0; i < mParam.numMinSize; ++i) |
| 76 | { |
| 77 | PLUGIN_VALIDATE(mParam.minSize[i] > 0.F, "minSize must be positive"); |
| 78 | } |
| 79 | mMinSizeGPU = copyToDevice(mParam.minSize, mParam.numMinSize); |
| 80 | |
| 81 | PLUGIN_VALIDATE(mParam.numAspectRatios >= 0); |
| 82 | PLUGIN_VALIDATE(mParam.aspectRatios != nullptr); |
| 83 | // Aspect ratio of 1.0 is built in. |
| 84 | std::vector<float> tmpAR(1, 1); |
| 85 | for (int32_t i = 0; i < mParam.numAspectRatios; ++i) |
| 86 | { |
| 87 | float aspectRatio = mParam.aspectRatios[i]; |
| 88 | bool alreadyExist = false; |
| 89 | // Prevent duplicated aspect ratios from input |
| 90 | for (size_t j = 0; j < tmpAR.size(); ++j) |
| 91 | { |
| 92 | if (std::fabs(aspectRatio - tmpAR[j]) < 1e-6) |
| 93 | { |
| 94 | alreadyExist = true; |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | if (!alreadyExist) |
| 99 | { |
| 100 | PLUGIN_VALIDATE(aspectRatio > 0.F); |
| 101 | tmpAR.push_back(aspectRatio); |
| 102 | if (mParam.flip) |
| 103 | { |
| 104 | tmpAR.push_back(1.0F / aspectRatio); |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | // |
| 109 | // mAspectRatiosGPU is of type nvinfer1::Weights. |
| 110 | // https://docs.nvidia.com/deeplearning/sdk/tensorrt-api/c_api/classnvinfer1_1_1_weights.html |
| 111 | // mAspectRatiosGPU.count is different to mParam.numAspectRatios. |
| 112 | // |
| 113 | mAspectRatiosGPU = copyToDevice(&tmpAR[0], tmpAR.size()); |
| 114 | |
| 115 | // Number of prior boxes per grid cell on the feature map |
| 116 | // tmpAR already included an aspect ratio of 1.0 |
| 117 | mNumPriors = tmpAR.size() * mParam.numMinSize; |
| 118 | |
| 119 | // |
nothing calls this directly
no test coverage detected