| 248 | } |
| 249 | |
| 250 | TEST(TRT_ShapedWeights_Test, Basic) { |
| 251 | // Test constructor with no arguments. |
| 252 | { |
| 253 | TRT_ShapedWeights weights; |
| 254 | TRT_ShapedWeights copy(weights); |
| 255 | for (auto ptr : {&weights, ©}) { |
| 256 | nvinfer1::Weights trt_weights = ptr->GetTrtWeights(); |
| 257 | EXPECT_EQ(nvinfer1::DataType::kFLOAT, trt_weights.type); |
| 258 | EXPECT_EQ(nullptr, trt_weights.values); |
| 259 | EXPECT_EQ(0, trt_weights.count); |
| 260 | |
| 261 | EXPECT_EQ(nullptr, ptr->GetValues()); |
| 262 | EXPECT_EQ(0, ptr->count()); |
| 263 | EXPECT_EQ(0, ptr->size_bytes()); |
| 264 | } |
| 265 | } |
| 266 | // Test constructor with DataType argument. |
| 267 | { |
| 268 | TRT_ShapedWeights weights(nvinfer1::DataType::kFLOAT); |
| 269 | TRT_ShapedWeights copy(weights); |
| 270 | for (auto ptr : {&weights, ©}) { |
| 271 | nvinfer1::Weights trt_weights = ptr->GetTrtWeights(); |
| 272 | EXPECT_EQ(nvinfer1::DataType::kFLOAT, trt_weights.type); |
| 273 | EXPECT_EQ(nullptr, trt_weights.values); |
| 274 | EXPECT_EQ(0, trt_weights.count); |
| 275 | |
| 276 | EXPECT_EQ(nullptr, ptr->GetValues()); |
| 277 | EXPECT_EQ(0, ptr->count()); |
| 278 | EXPECT_EQ(0, ptr->size_bytes()); |
| 279 | } |
| 280 | } |
| 281 | // Test constructor with DataType and nvinfer1::Dims arguments. |
| 282 | { |
| 283 | TrtWeightStore store; |
| 284 | TRT_ShapedWeights weights = |
| 285 | store.GetTempWeights(nvinfer1::DataType::kFLOAT, GetTestDims({2, 5})); |
| 286 | TRT_ShapedWeights copy(weights); |
| 287 | for (auto ptr : {&weights, ©}) { |
| 288 | nvinfer1::Weights trt_weights = ptr->GetTrtWeights(); |
| 289 | EXPECT_EQ(nvinfer1::DataType::kFLOAT, trt_weights.type); |
| 290 | EXPECT_NE(nullptr, trt_weights.values); |
| 291 | EXPECT_EQ(10, trt_weights.count); |
| 292 | |
| 293 | EXPECT_EQ(trt_weights.values, ptr->GetValues()); |
| 294 | EXPECT_EQ(10, ptr->count()); |
| 295 | EXPECT_EQ(40, ptr->size_bytes()); |
| 296 | } |
| 297 | // Test that it doesn't copy the underlying buffer. |
| 298 | EXPECT_EQ(weights.GetValues(), copy.GetValues()); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | TEST(TRT_TensorOrWeights_Test, Basic) { |
| 303 | // Test constructor with no arguments. |
nothing calls this directly
no test coverage detected