| 154 | } |
| 155 | |
| 156 | intl::SimpleQuantizedTensorRTNetwork::SimpleQuantizedTensorRTNetwork() { |
| 157 | host_x = range_gen({32, 8, 28, 28}); |
| 158 | host_w = weight_gen({8, 8, 3, 3}); |
| 159 | host_b = range_gen({1, 8, 1, 1}); |
| 160 | |
| 161 | { |
| 162 | void* w_ptr = host_w->raw_ptr(); |
| 163 | float* ptr = reinterpret_cast<float*>(w_ptr); |
| 164 | ptr[0] = -127 * 1.1f; |
| 165 | ptr[1] = 127 * 1.1f; |
| 166 | } |
| 167 | |
| 168 | graph = ComputingGraph::make(); |
| 169 | auto mkvar = [this](const char* name, const std::shared_ptr<HostTensorND>& host_ts, |
| 170 | const DType& dtype) { |
| 171 | return opr::TypeCvt::make( |
| 172 | opr::Host2DeviceCopy::make(*graph, host_ts).rename(name), dtype); |
| 173 | }; |
| 174 | auto mkcvar = [this](const char* name, const std::shared_ptr<HostTensorND>& host_ts, |
| 175 | const DType& dtype) { |
| 176 | return opr::TypeCvt::make( |
| 177 | opr::SharedDeviceTensor::make(*graph, *host_ts).rename(name), dtype); |
| 178 | }; |
| 179 | |
| 180 | x = mkvar("x", host_x, dtype::Float32()); |
| 181 | quantized_x = mkvar("quantized_x", host_x, dtype::QuantizedS8(1.2f)); |
| 182 | auto float_w = mkcvar("float_w", host_w, dtype::Float32()), |
| 183 | float_b = mkcvar("float_b", host_b, dtype::Float32()), |
| 184 | w = opr::TypeCvt::make(float_w, dtype::QuantizedS8(1.1f)), |
| 185 | b = opr::TypeCvt::make(float_b, dtype::QuantizedS32(1.2f * 1.1f)); |
| 186 | |
| 187 | { |
| 188 | auto xshp = opr::GetVarShape::make(quantized_x); |
| 189 | |
| 190 | auto cv = [this](int v) { return quantized_x.make_scalar(v); }; |
| 191 | auto sub = [&xshp, &cv](int idx) { |
| 192 | return opr::IndexAt::make(xshp, {{0, cv(idx)}}); |
| 193 | }; |
| 194 | auto tshp = opr::Concat::make({sub(0), sub(1) / 4, cv(4), sub(2), sub(3)}, 0); |
| 195 | quantized_x = opr::Reshape::make(quantized_x, tshp); |
| 196 | quantized_x = opr::Dimshuffle::make(quantized_x, {0, 1, 3, 4, 2}); |
| 197 | } |
| 198 | |
| 199 | { |
| 200 | auto wshp = opr::GetVarShape::make(w); |
| 201 | |
| 202 | auto cv = [&w](int v) { return w.make_scalar(v); }; |
| 203 | auto sub = [&wshp, &cv](int idx) { |
| 204 | return opr::IndexAt::make(wshp, {{0, cv(idx)}}); |
| 205 | }; |
| 206 | auto tshp = opr::Concat::make({sub(0), sub(1) / 4, cv(4), sub(2), sub(3)}, 0); |
| 207 | w = opr::Reshape::make(w, tshp); |
| 208 | w = opr::Dimshuffle::make(w, {0, 1, 3, 4, 2}); |
| 209 | } |
| 210 | |
| 211 | { |
| 212 | auto bshp = opr::GetVarShape::make(b); |
| 213 |
nothing calls this directly
no test coverage detected