Created
May 7, 2019 00:30
-
-
Save tytydraco/ce88e8b13c69c8fc7913da34b46508fc to your computer and use it in GitHub Desktop.
Cubic + Linear Interpolation + Extrapolation for QCOM Energy Model Porting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Tyler Nijmeh <tylernij@gmail.com> | |
from scipy import interpolate | |
# P.S.: The default target values are from sdm660 | |
# P.S.: The default source values are from sdm632 | |
# Target frequencies | |
target_cluster0_freqs = [633600, 902400, 1113600, 1401600, 1536000, 1747200, 1843200] | |
target_cluster1_freqs = [1113600, 1401600, 1747200, 1804800, 1958400, 2150400, 2208000] | |
# Source frequencies | |
src_cluster0_freqs = [614400, 883200, 1036800, 1363200, 1536000, 1670400, 1804800] | |
src_cluster1_freqs = [633600, 902400, 1094400, 1401600, 1555200, 1804800, 1996000, 2016000] | |
# Source costs | |
src_core0_costs = [23, 41, 56, 88, 112, 151, 194] | |
src_core1_costs = [722, 1287, 1739, 2819, 3532, 5038, 6624, 6688] | |
src_cluster0_costs = [8, 14, 18, 28, 35, 43, 54] | |
src_cluster1_costs = [68, 103, 132, 193, 233, 292, 374, 377] | |
# Interpolate | |
def interp(src_freqs, src_costs, target_freqs): | |
# Interpolated values | |
interp_target_freqs = [] | |
interp_src_freqs = [] | |
interp_src_costs = [] | |
# Extrapolated values | |
extrap_target_freqs = [] | |
# Sort freqs and costs into either interp or extrap | |
max_src_freq = src_freqs[len(src_freqs)-1] | |
for idx in range(0, len(target_freqs)): | |
if target_freqs[idx] <= max_src_freq: | |
interp_target_freqs.append(target_freqs[idx]) | |
interp_src_freqs.append(src_freqs[idx]) | |
interp_src_costs.append(src_costs[idx]) | |
else: | |
extrap_target_freqs.append(target_freqs[idx]) | |
# Use more accurate cubic spline interpolation when target <= source freqs | |
c_f = interpolate.interp1d(src_freqs, src_costs, kind='cubic') | |
for freq in interp_target_freqs: | |
print('%d %.0f' % (freq, c_f(freq))) | |
# Use linear spline interpolation if we can't accurately extrapolate the cubic spline | |
l_f = interpolate.interp1d(src_freqs, src_costs, kind='slinear', fill_value='extrapolate') | |
for freq in extrap_target_freqs: | |
print('%d %.0f' % (freq, l_f(freq))) | |
# Newline | |
print("") | |
# Interpolate for core0, core1, cluster0, cluster1 | |
print("Energy Model Interpolation Script") | |
print("By Tyler Nijmeh <tylernij@gmail.com>") | |
print("") | |
print("--- CORE0 ---") | |
interp(src_cluster0_freqs, src_core0_costs, target_cluster0_freqs) | |
print("--- CORE1 ---") | |
interp(src_cluster1_freqs, src_core1_costs, target_cluster1_freqs) | |
print("--- CLUSTER0 ---") | |
interp(src_cluster0_freqs, src_cluster0_costs, target_cluster0_freqs) | |
print("--- CLUSTER1 ---") | |
interp(src_cluster1_freqs, src_cluster1_costs, target_cluster1_freqs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment