| 344 | } |
| 345 | |
| 346 | void QuantizedBiasAdd(OpKernelContext* tf_context, const quint8* input, |
| 347 | int input_count, const quint8* bias, int bias_count, |
| 348 | float input_min, float input_max, float bias_min, |
| 349 | float bias_max, float output_min, float output_max, |
| 350 | qint32* output) { |
| 351 | #ifdef TENSORFLOW_USE_META |
| 352 | mutex_lock library_lock(GetMutex()); |
| 353 | typedef gemmlowp::meta::Transform1DParams<uint8_t, int32_t, |
| 354 | gemmlowp::meta::BiasAdd<uint8_t>> |
| 355 | Params; |
| 356 | |
| 357 | Params params; |
| 358 | params.input = reinterpret_cast<const uint8_t*>(input); |
| 359 | params.output = reinterpret_cast<int32_t*>(output); |
| 360 | params.kernel.bias = reinterpret_cast<const uint8_t*>(bias); |
| 361 | params.kernel.count = bias_count; |
| 362 | params.kernel.rows = input_count / bias_count; |
| 363 | params.kernel.input_range_min = input_min; |
| 364 | params.kernel.bias_range_min = bias_min; |
| 365 | params.kernel.input_range_scale = |
| 366 | CalculateRangeScale<uint8_t>(input_min, input_max); |
| 367 | params.kernel.bias_range_scale = |
| 368 | CalculateRangeScale<uint8_t>(bias_min, bias_max); |
| 369 | params.kernel.input_range_offset = 0; |
| 370 | params.kernel.bias_range_offset = 0; |
| 371 | params.kernel.output_range_min = output_min; |
| 372 | params.kernel.one_over_output_range_scale = |
| 373 | CalculateOneOverRangeScale<int32_t>(output_min, output_max); |
| 374 | params.kernel.output_range_offset = |
| 375 | static_cast<float>(std::numeric_limits<int32_t>::lowest()); |
| 376 | |
| 377 | // TODO(maciekc): add multithreading to bias add. |
| 378 | // Right now this kernel does not support multi threaded execution. |
| 379 | gemmlowp::meta::Transform1D<Params, 16>(params); |
| 380 | #else |
| 381 | LOG(FATAL) << "QuantizedBiasAdd: Meta fastpath not supported."; |
| 382 | #endif |
| 383 | } |
| 384 | |
| 385 | void Clamp(OpKernelContext* tf_context, const quint8* input, int count, |
| 386 | quint8 clamp_min, quint8 clamp_max, quint8* output) { |