| 22 | namespace nvcaffeparser1 |
| 23 | { |
| 24 | ILayer* parsePower(INetworkDefinition& network, const trtcaffe::LayerParameter& msg, CaffeWeightFactory& weightFactory, BlobNameToTensor& tensors) |
| 25 | { |
| 26 | if (!checkBlobs(msg, 1, 1)) |
| 27 | { |
| 28 | return nullptr; |
| 29 | } |
| 30 | |
| 31 | const trtcaffe::PowerParameter& p = msg.power_param(); |
| 32 | |
| 33 | float shift = p.has_shift() ? p.shift() : 0.0f; |
| 34 | float scale = p.has_scale() ? p.scale() : 1.0f; |
| 35 | float power = p.has_power() ? p.power() : 1.0f; |
| 36 | |
| 37 | DataType dataType = weightFactory.getDataType(); |
| 38 | assert(dataType == DataType::kFLOAT || dataType == DataType::kHALF); |
| 39 | |
| 40 | Weights wShift, wScale, wPower; |
| 41 | if (dataType == DataType::kHALF) |
| 42 | { |
| 43 | auto* t = reinterpret_cast<float16*>(malloc(3 * sizeof(float16))); |
| 44 | t[0] = float16(shift), t[1] = float16(scale), t[2] = float16(power); |
| 45 | wShift = Weights{DataType::kHALF, &t[0], 1}; |
| 46 | wScale = Weights{DataType::kHALF, &t[1], 1}; |
| 47 | wPower = Weights{DataType::kHALF, &t[2], 1}; |
| 48 | weightFactory.getTmpAllocs().push_back(t); |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | auto* t = reinterpret_cast<float*>(malloc(3 * sizeof(float))); |
| 53 | t[0] = shift, t[1] = scale, t[2] = power; |
| 54 | wShift = Weights{DataType::kFLOAT, &t[0], 1}; |
| 55 | wScale = Weights{DataType::kFLOAT, &t[1], 1}; |
| 56 | wPower = Weights{DataType::kFLOAT, &t[2], 1}; |
| 57 | weightFactory.getTmpAllocs().push_back(t); |
| 58 | } |
| 59 | |
| 60 | weightFactory.convert(wShift); |
| 61 | weightFactory.convert(wScale); |
| 62 | weightFactory.convert(wPower); |
| 63 | return network.addScale(*tensors[msg.bottom(0)], ScaleMode::kUNIFORM, wShift, wScale, wPower); |
| 64 | } |
| 65 | } //namespace nvcaffeparser1 |
nothing calls this directly
no test coverage detected