Imported from https://github.com/vladk17/ml_perf_optimizations