Przeglądaj źródła

Set ADC parameters and setup expr directory

Youngbin Kim 5 miesięcy temu
rodzic
commit
b92948ffbf

+ 5 - 4
Core/Src/ImC/imc_api.c

@@ -264,7 +264,8 @@ int medianCalc(int* input, int arr_size){
 // uint16_t MEAS_COEF[2] = {812, 782};	// for EPS CAP ch0 and ch1
 // uint16_t MEAS_COEF[2] = {700, 782};	// imc, 10mF
 // uint16_t MEAS_COEF[2] = {765, 782};	// imc, 4.7mF, voltage divider
-uint16_t MEAS_COEF[2] = {771, 782};	// imc, 4.7mF, voltage divider
+// uint16_t MEAS_COEF[2] = {771, 782};	// imc, 4.7mF, voltage divider
+uint16_t MEAS_COEF[2] = {1050, 782};	// imc, 4.7mF, voltage divider
 int measure_voltage(ADC_HandleTypeDef hadc, uint8_t ch){
 	int val;
 	// for(int i=0; i<100; i++) { __ASM(" nop"); }
@@ -293,9 +294,9 @@ int measure_voltage(ADC_HandleTypeDef hadc, uint8_t ch){
 	}
 
 	int v_value = ((uint32_t)medianCalc(res_value, n_evals)) * MEAS_COEF[ch] / 500; //
-//	int voltage_d = v_value/1000;
-//	int voltage_f = v_value%1000;
-//	printf("ADC Value:     %d.%03d \r\n", voltage_d, voltage_f);
+	// int voltage_d = v_value/1000;
+	// int voltage_f = v_value%1000;
+	// printf("ADC Value:     %d.%03d \r\n", voltage_d, voltage_f);
 	return v_value;
 }
 

Plik diff jest za duży
+ 0 - 39
imc/exprs/dac2025/1_measure_timings/draw_graph_expr_1.ipynb


+ 0 - 94
imc/exprs/dac2025/1_measure_timings/draw_graph_expr_1.py

@@ -1,94 +0,0 @@
-import pickle
-import pandas as pd
-import seaborn as sns
-import pprint
-
-from imc_utils.oscilloscope_dsox1204a import CommonOperations
-
-def draw_graph():
-    with open("output/sample_result.pickle", "rb") as f:
-        result = pickle.load(f)
-    df = pd.DataFrame(result["results"])
-    info = result["info"]
-    x_increment = info["x_increment"]
-
-    print(info)
-    eps_intervals = CommonOperations.get_high_intervals(df["eps"], 3)
-    task_intervals = CommonOperations.get_high_intervals(df["task"], 1)
-
-    eps_lengths = [ v[1] - v[0] for v in eps_intervals]
-    task_lengths = [ v[1] - v[0] for v in task_intervals]
-
-    iterations = []
-
-    for i in range(len(eps_intervals)):
-        eps_interval = eps_intervals[i]
-        eps_start = eps_interval[0]
-
-        iteration = None
-        
-        if i == len(eps_intervals)-1:
-            next_eps_start = float("inf")
-        else:
-            next_eps_interval = eps_intervals[i+1]
-            next_eps_start = next_eps_interval[0]
-
-        for task_interval in task_intervals:
-            task_start = task_interval[0]
-            if eps_start <= task_start and task_start <= next_eps_start:
-                iteration = {
-                    "eps": eps_interval,
-                    "task": task_interval
-                }
-                break
-        
-        if iteration is None:
-            iteration = {
-                "eps": eps_interval,
-                "task": None,
-            }
-
-        iterations.append(iteration)
-
-    results = []
-
-    for iteration in iterations:
-        eps_interval = iteration["eps"]
-        task_interval = iteration["task"]
-        eps_duration = eps_interval[1] - eps_interval[0]
-        eps_duration *= x_increment * 1000
-        task_duration = task_interval[1] - task_interval[0] if not task_interval is None else 0
-        task_duration *= x_increment * 1000
-        ratio = task_duration / eps_duration
-        results.append({
-            "eps_duration": eps_duration,
-            "task_duration": task_duration,
-            "ratio": ratio,
-        })
-    
-    d = pd.DataFrame(results)
-    print(d)
-    total_eps_duration = d["eps_duration"].sum()
-    total_task_duration = d["task_duration"].sum()
-
-    average_eps_duration = d["eps_duration"].mean()
-    average_task_duration = d["task_duration"].mean()
-    overhead_ticks = total_eps_duration - total_task_duration
-    average_overhead_ticks = overhead_ticks / len(d)
-    print("total eps duration:", total_eps_duration)
-    print("total task duration:", total_task_duration)
-    print("efficiency:", total_task_duration/total_eps_duration)
-    print(f"average eps duration: {average_eps_duration:.3f} ms")
-    print(f"average task duration: {average_task_duration:.3f} ms")
-    print(f"average wasted: {average_overhead_ticks:.3f} ms")
-
-    g = sns.lineplot(df)
-    g.grid()
-    g.set_ylim([-1, 4])
-
-    for (start, end) in eps_intervals:
-        g.axvspan(start, end, alpha=0.3)
-
-    for (start, end) in task_intervals:
-        g.axvspan(start, end, facecolor="b", alpha=0.3)
-    

+ 0 - 55
imc/exprs/dac2025/1_measure_timings/run_expr_1.py

@@ -1,55 +0,0 @@
-import pickle
-import time
-
-from imc_utils.oscilloscope_dsox1204a import DSOX1204A
-from imc_utils.pps_e36311a import PPS_E36311A
-
-scope = DSOX1204A()
-
-timebase = 1
-scope.set_volt_scale(3, 1)
-scope.set_timebase(timebase)
-scope.set_timebase_reference_left()
-scope.set_trigger_rising_edge(3, 3)
-scope.set_acquisition_type("hresolution")
-scope.aquire_single()
-
-pps = PPS_E36311A()
-# target_current = 0.005
-# target_voltage = 1
-target_current = 0.002
-target_voltage = 3.3
-pps.set_current(target_current, 1)
-pps.set_voltage(target_voltage, 1)
-pps.output_on(1)
-
-time.sleep(timebase * 10 + 3)
-
-print("receiving vdd")
-result_vdd = scope.get_waveform(1)
-print("receiving task")
-result_task = scope.get_waveform(2)
-print("receiving eps")
-result_eps = scope.get_waveform(3)
-
-print("x increment:", scope.get_xincrement())
-
-pps.output_off(1)
-
-results = {
-    "vdd": result_vdd,
-    "task": result_task,
-    "eps": result_eps
-}
-info = {
-    "x_increment": scope.get_xincrement(),
-    "target_current": target_current,
-}
-
-output = {
-    "results": results,
-    "info": info,
-}
-
-with open("output/sample_result.pickle", "wb") as f:
-    pickle.dump(output, f)

Plik diff jest za duży
+ 0 - 42
imc/exprs/dac2025/2_error_low_voltage/draw_graph_expr_2.ipynb


+ 0 - 59
imc/exprs/dac2025/2_error_low_voltage/draw_graph_expr_2.py

@@ -1,59 +0,0 @@
-import pickle
-import os
-import pandas as pd
-import seaborn as sns
-import matplotlib.pyplot as plt
-import matplotlib.ticker
-from scipy import stats
-import numpy as np
-
-import plot_utils
-
-def draw_graph():
-    with open("output/adc_demo.pickle", "rb") as f:
-        df = pickle.load(f)
-    
-    with open("output/voltage_real.pickle", "rb") as f:
-        voltage_scope = pickle.load(f)
-
-    x_tick = 0.000130208333
-
-    # make the first tick to be 100ms
-    first_tick = df.iloc[0]["tick"]
-    tick_to_ms = 1000 / 32_000_000
-    df["ms"] = 100 + (df["tick"] - first_tick) * tick_to_ms
-    print(df)
-
-    df_eps_off = df[df["eps_on"] == False]
-    eps_off_start, eps_off_end = df_eps_off.iloc[0]["ms"], df_eps_off.iloc[-1]["ms"]
-    print(eps_off_start, eps_off_end)
-
-    df2 = pd.DataFrame(voltage_scope)
-    df2["ms"] = df2.index * x_tick * 1000
-    df2.columns = ["voltage_real", "ms"]
-
-    plot_utils.set_theme_seaborn(kind="line")
-
-    g = sns.lineplot(
-        df,
-        x = "ms",
-        y = "voltage_adc",
-        label = "From ADC",
-    )
-    sns.lineplot(
-        df2,
-        x = "ms",
-        y = "voltage_real",
-        label = "Measurement",
-    )
-
-    g.axvspan(eps_off_start, eps_off_end, color = "lightgray", alpha=0.6)
-
-    g.set_xlim([100, 750])
-    g.legend()
-    g.set_ylabel("Capacitor voltage (V)")
-    g.set_xlabel("Time after boot (ms)")
-
-    print("4.7mF, 10mA, 3.3V")
-
-    return g

+ 0 - 171
imc/exprs/dac2025/2_error_low_voltage/run_expr_2.py

@@ -1,171 +0,0 @@
-import tempfile
-import time
-import pickle
-import pandas as pd
-
-from imc_utils.pps_e36311a import PPS_E36311A
-from imc_utils.smu_b2902a import SMU_B2902A
-from imc_utils.build_config.cortex_m33 import BuildConfigM33
-from imc_utils.build_config.test_env import TestEnv
-from imc_utils.serial_watch import SerialWatcher
-from imc_utils.oscilloscope_dsox1204a import DSOX1204A
-
-import imc_utils.serial_device
-
-WORKSPACE_ROOT = "/home/ybkim/workspace/imc/imc_freertos_app_m33"
-NVM_RESET_BIN = f"{WORKSPACE_ROOT}/imc/utils/nvm_reset.elf"
-OPENOCD_SCRIPT = f"{WORKSPACE_ROOT}/imc_freertos_app_m33.cfg"
-
-use_smu = False
-
-# pin setup: scope #3 -> EPS capacitor voltage
-# pin setup: GPIO PF10 -> EPS on signal
-
-def main():
-    pps = PPS_E36311A()
-
-    if use_smu:
-        volt = 3.3
-        smu = SMU_B2902A(voltage=3.3)
-    config = get_default_build_config()
-
-    scope = DSOX1204A()
-
-    timebase = 0.1
-    scope.set_volt_scale(3, 2)
-    scope.set_timebase(timebase)
-    scope.set_timebase_reference_left()
-    scope.set_trigger_rising_edge(2, 3)
-    scope.set_acquisition_type("hresolution")
-
-    benchmark = "adc_demo"
-
-    total_iterations = 1
-    target_current_limit = 0.010
-
-    all_records = []
-    config.bench_name = benchmark
-
-    if use_smu:
-        smu.set_current_limit(0.1)
-        smu.power_on()
-    else:
-        pps.set_voltage(3.3, 1)
-        pps.set_current(0.1, 1)
-        pps.output_on(1)
-
-    env = TestEnv(WORKSPACE_ROOT, NVM_RESET_BIN, OPENOCD_SCRIPT)
-
-    with tempfile.TemporaryDirectory() as build_dir:
-        binary = env.build_binary(config, build_dir)
-        env.clear_nvm_and_load_binary(binary, resume=False)
-
-    if use_smu:
-        smu.set_current_limit(target_current_limit)
-    else:
-        pps.set_current(target_current_limit, 1)
-
-    time.sleep(1)
-
-    env.resume_board(terminate=True)
-
-    ser = imc_utils.serial_device.get_serial()
-    lines = []
-    start_deteced = False
-
-    time.sleep(2)
-
-    ser.read_all()
-    while True:
-        if ser.readable():
-            res = ser.readline()
-            try:
-                line = res.decode()[: len(res) - 1]
-                line = line.strip()
-            except:
-                continue
-
-            if line.startswith("Start benchmark"):
-                if start_deteced is False:
-                    start_deteced = True
-                    scope.aquire_single()
-                    continue
-                else:
-                    break
-            if start_deteced:
-                lines.append(line)
-    
-    results = []
-
-    results_real = scope.get_waveform(3)
-    print(results_real)
-
-    x_increment = scope.get_xincrement()
-
-    for line in lines:
-        try:
-            tick, eps_on, voltage = line.split()
-            tick = int(tick.strip())
-            eps_on = True if eps_on.strip() == "1" else False
-            voltage = float(voltage.strip())
-            results.append({
-                "tick": tick,
-                "eps_on": eps_on,
-                "voltage_adc": voltage,
-            })
-        except:
-            continue
-
-    first_voltage_tick = results[0]["tick"]
-    print(x_increment)
-
-    # def tick_to_waveform_index(tick):
-    #     tick_offset = tick - first_voltage_tick
-    #     waveform_offset = int(timebase / x_increment)
-    #     x_increment_to_ms = 0.001 / x_increment
-    #     return waveform_offset + int(tick_offset * x_increment_to_ms)
-
-    # for result in results:
-    #     tick = result["tick"]
-    #     result.update({
-    #         "voltage_real": results_real[tick_to_waveform_index(tick)],
-    #         "index": tick_to_waveform_index(tick),
-    #     })
-
-    df = pd.DataFrame(results)
-    print(df)
-    save_records(benchmark, df)
-
-    with open("output/voltage_real.pickle", "wb") as f:
-        pickle.dump(results_real, f)
-
-    if use_smu:
-        smu.power_off()
-    else:
-        pps.output_off(1)
-
-
-def get_default_build_config():
-    config = BuildConfigM33()
-    config.insert_compiler_checkpoints = False
-    config.enable_extension = True
-    config.use_checkpoint_pass_counter = False
-    config.use_checkpoint_voltage_check = False
-    config.bench_infinite_loop = True
-    config.print_recovery_message = True
-    config.split_loop = False
-    config.enable_static_loop_pass_count = False
-    config.enable_adaptive_loop_pass_count = False
-    config.print_stats = True
-    config.custom_unroll = False
-    config.loop_opt_debug = False
-    return config
-
-
-def save_records(bench_name, df):
-    with open(f"output/{bench_name}.pickle", "wb") as f:
-        pickle.dump(df, f)
-
-
-if __name__ == "__main__":
-    main()

Plik diff jest za duży
+ 0 - 88
imc/exprs/dac2025/3_fmc_error/draw_graph_expr_3.ipynb


+ 0 - 78
imc/exprs/dac2025/3_fmc_error/draw_graph_expr_3.py

@@ -1,78 +0,0 @@
-import pickle
-import os
-import pandas as pd
-import seaborn as sns
-import matplotlib.pyplot as plt
-import matplotlib.ticker
-from scipy import stats
-import numpy as np
-
-import plot_utils
-
-
-def draw_graph():
-    with open("output/fmc_expr.pickle", "rb") as f:
-        df = pickle.load(f)
-
-    with open("output/vdd.pickle", "rb") as f:
-        vdd = pickle.load(f)
-
-    x_tick = 6.51041666e-05
-
-    # make the first tick to be 50ms
-    first_tick = df.iloc[0]["tick"]
-    tick_to_ms = 1000 / 32_000_000
-    df["ms"] = 50 + (df["tick"] - first_tick) * tick_to_ms
-    error_rates = [0]
-    for i in range(1, len(df)):
-        current = df.iloc[i]
-        prev = df.iloc[i-1]
-        sampled = current["total"] - prev["total"]
-        errors = current["errors"] - prev["errors"]
-        error_rates.append(100 * errors/sampled)
-    df["error_rate"] = error_rates
-    print(df.to_string())
-
-    # df_eps_off = df[df["eps_on"] == False]
-    # eps_off_start, eps_off_end = df_eps_off.iloc[0]["ms"], df_eps_off.iloc[-1]["ms"]
-    # print(eps_off_start, eps_off_end)
-
-    df2 = pd.DataFrame(vdd)
-    df2["ms"] = df2.index * x_tick * 1000
-    df2.columns = ["vdd", "ms"]
-
-    print(df2)
-
-    plot_utils.set_theme_seaborn(kind="line")
-
-    g = sns.lineplot(
-        df,
-        x="ms",
-        y="error_rate",
-        # marker=".",
-        label="FMC error rate",
-    )
-    ax2 = g.twinx()
-    sns.lineplot(
-        df2,
-        x="ms",
-        y="vdd",
-        label="Vdd",
-        linestyle="--",
-        color="cornflowerblue",
-        ax = ax2,
-    )
-
-    # g.axvspan(eps_off_start, eps_off_end, color="lightgray", alpha=0.6)
-
-    g.set_xlim([100, 350])
-    # g.legend()
-    g.set_ylabel("Memory error rate (%)")
-    g.set_xlabel("Time after boot (ms)")
-
-    ax2.set_ylabel("Voltage")
-    ax2.grid()
-
-    print("1mF, 15mA, 3.3V")
-
-    return g

+ 0 - 170
imc/exprs/dac2025/3_fmc_error/run_expr_3.py

@@ -1,170 +0,0 @@
-import tempfile
-import time
-import pickle
-import pandas as pd
-
-from imc_utils.pps_e36311a import PPS_E36311A
-from imc_utils.smu_b2902a import SMU_B2902A
-from imc_utils.build_config.cortex_m33 import BuildConfigM33
-from imc_utils.build_config.test_env import TestEnv
-from imc_utils.serial_watch import SerialWatcher
-from imc_utils.oscilloscope_dsox1204a import DSOX1204A
-
-import imc_utils.serial_device
-
-WORKSPACE_ROOT = "/home/ybkim/workspace/imc/imc_freertos_app_m33"
-NVM_RESET_BIN = f"{WORKSPACE_ROOT}/imc/utils/nvm_reset.elf"
-OPENOCD_SCRIPT = f"{WORKSPACE_ROOT}/imc_freertos_app_m33.cfg"
-
-use_smu = False
-
-
-def main():
-    pps = PPS_E36311A()
-
-    if use_smu:
-        volt = 3.3
-        smu = SMU_B2902A(voltage=3.3)
-    config = get_default_build_config()
-
-    scope = DSOX1204A()
-
-    timebase = 0.05
-    scope.set_volt_scale(3, 1)
-    scope.set_timebase(timebase)
-    scope.set_timebase_reference_left()
-    scope.set_trigger_rising_edge(2, 2)
-    scope.set_acquisition_type("hresolution")
-
-    benchmark = "fmc_expr"
-
-    total_iterations = 1
-    target_current_limit = 0.015
-
-    all_records = []
-    config.bench_name = benchmark
-
-    if use_smu:
-        smu.set_current_limit(0.1)
-        smu.power_on()
-    else:
-        pps.set_voltage(3.3, 1)
-        pps.set_current(0.1, 1)
-        pps.output_on(1)
-
-    env = TestEnv(WORKSPACE_ROOT, NVM_RESET_BIN, OPENOCD_SCRIPT)
-
-    with tempfile.TemporaryDirectory() as build_dir:
-        binary = env.build_binary(config, build_dir)
-        env.clear_nvm_and_load_binary(binary, resume=False)
-
-    if use_smu:
-        smu.set_current_limit(target_current_limit)
-    else:
-        pps.set_current(target_current_limit, 1)
-
-    time.sleep(1)
-
-    env.resume_board(terminate=True)
-
-    ser = imc_utils.serial_device.get_serial()
-    lines = []
-    start_deteced = False
-
-    time.sleep(2)
-
-    ser.read_all()
-    while True:
-        if ser.readable():
-            res = ser.readline()
-            try:
-                line = res.decode()[: len(res) - 1]
-                line = line.strip()
-            except:
-                continue
-
-            if line.startswith("Start benchmark"):
-                if start_deteced is False:
-                    start_deteced = True
-                    scope.aquire_single()
-                    continue
-                else:
-                    break
-            if start_deteced:
-                lines.append(line)
-
-    results = []
-
-    vdd = scope.get_waveform(1)
-    print(vdd)
-
-    x_increment = scope.get_xincrement()
-
-    for line in lines:
-        try:
-            tick, errors, total = line.split()
-            tick = int(tick.strip())
-            errors = int(errors.strip())
-            total = int(total.strip())
-            results.append(
-                {
-                    "tick": tick,
-                    "errors": errors,
-                    "total": total
-                }
-            )
-        except:
-            continue
-
-    print(x_increment)
-
-    # def tick_to_waveform_index(tick):
-    #     tick_offset = tick - first_voltage_tick
-    #     waveform_offset = int(timebase / x_increment)
-    #     x_increment_to_ms = 0.001 / x_increment
-    #     return waveform_offset + int(tick_offset * x_increment_to_ms)
-
-    # for result in results:
-    #     tick = result["tick"]
-    #     result.update({
-    #         "voltage_real": results_real[tick_to_waveform_index(tick)],
-    #         "index": tick_to_waveform_index(tick),
-    #     })
-
-    df = pd.DataFrame(results)
-    print(df)
-    save_records(benchmark, df)
-
-    with open("output/vdd.pickle", "wb") as f:
-        pickle.dump(vdd, f)
-
-    if use_smu:
-        smu.power_off()
-    else:
-        pps.output_off(1)
-
-
-def get_default_build_config():
-    config = BuildConfigM33()
-    config.insert_compiler_checkpoints = False
-    config.enable_extension = True
-    config.use_checkpoint_pass_counter = False
-    config.use_checkpoint_voltage_check = False
-    config.bench_infinite_loop = True
-    config.print_recovery_message = False
-    config.split_loop = False
-    config.enable_static_loop_pass_count = False
-    config.enable_adaptive_loop_pass_count = False
-    config.print_stats = False
-    config.custom_unroll = False
-    config.loop_opt_debug = False
-    return config
-
-
-def save_records(bench_name, df):
-    with open(f"output/{bench_name}.pickle", "wb") as f:
-        pickle.dump(df, f)
-
-
-if __name__ == "__main__":
-    main()

Plik diff jest za duży
+ 0 - 66
imc/exprs/dac2025/4_energy_efficiency/draw_graph_expr_4.ipynb


+ 0 - 152
imc/exprs/dac2025/4_energy_efficiency/draw_graph_expr_4.py

@@ -1,152 +0,0 @@
-import pickle
-import os
-import pandas as pd
-import seaborn as sns
-import matplotlib.pyplot as plt
-import matplotlib.ticker
-from scipy import stats
-import numpy as np
-
-import plot_utils
-from imc_utils.oscilloscope_dsox1204a import CommonOperations
-
-def merge_and_analyze_df(df_smu, df_scope):
-    df_smu["watt"] = df_smu["curr"] * df_smu["volt"]
-
-    df_scope = df_scope.drop(df_scope.tail(3).index)
-    df_scope["in_execution"] = df_scope["in_execution"].abs() > 1
-    df_scope["eps_on"] = df_scope["eps_on"].abs() > 1
-
-    timestamp_offset = df_smu.iloc[-1]["timestamp"] - df_scope.iloc[-1]["timestamp"]
-    df_smu["time_synced"] = df_smu["timestamp"] - timestamp_offset
-
-    time_resolution = df_scope.iloc[1]["timestamp"]
-    ratio = np.round(df_smu["time_synced"] / time_resolution)
-    df_smu["time_res_synced"] = ratio * time_resolution
-    duplicated_rows = df_smu.duplicated("time_res_synced", keep="first")
-    df_smu = df_smu[duplicated_rows == False]
-
-    df_smu_simple = df_smu.drop(columns=["curr", "volt", "timestamp", "time_synced"])
-    df_smu_simple = df_smu_simple.rename(
-        columns = {"time_res_synced": "timestamp"}
-    )
-    df = pd.merge(df_scope, df_smu_simple, how="left", on="timestamp")
-
-    results = []
-
-    eps_falling_edges = CommonOperations.get_falling_edge_index(df["eps_on"], 0.9)
-    eps_joules = []
-    for i in range(len(eps_falling_edges)-1):
-        start = eps_falling_edges[i]
-        end = eps_falling_edges[i+1]
-        watts = df.iloc[start:end+1]["watt"]
-        energy = watts.sum() * time_resolution
-        eps_joules.append(energy)
-
-        results.append({
-            "charge_start": df.iloc[start]["timestamp"],
-            "charge_end": df.iloc[end]["timestamp"],
-            "input_energy": energy,
-            "watt": watts.mean(),
-        })
-
-    in_execution_intervals = CommonOperations.get_high_intervals(df["in_execution"], 0.9)
-
-    for execution_interval in in_execution_intervals:
-        execution_start, execution_end = execution_interval
-        mask = execution_start - np.array(eps_falling_edges)
-        mask = np.where(mask > 0)
-        indices = mask[0]
-        if indices.size == 0:
-            continue
-        index = indices[-1]
-        if index == len(results):
-            continue
-
-        start_time = df.iloc[execution_start]["timestamp"]
-        end_time = df.iloc[execution_end]["timestamp"]
-        results[index].update({
-            "execution_start": start_time,
-            "execution_end": end_time,
-            "execution_time": end_time - start_time,
-        })
-
-    result = pd.DataFrame(results)
-
-    if result.empty:
-        return result
-    
-    execution_columns = ["execution_start", "execution_end", "execution_time"]
-    for col in execution_columns:
-        if col not in result.columns:
-            result[col] = np.nan
-
-    mask = np.isnan(result["execution_time"])
-    result.loc[mask, "execution_time"] = 0
-    result["time_per_energy"] = result["execution_time"] / result["input_energy"]
-
-    return result
-
-def print_stat_summary(df):
-    average_time_per_energy = df["time_per_energy"].mean()
-    average_execution_time = df[df["execution_time"] != 0]["execution_time"].mean()
-    average_power = df["watt"].mean()
-
-    print(f"average time per energy (s/j): {average_time_per_energy:.3f}")
-    print(f"average execution duration (ms): {average_execution_time*1000:.3f}")
-    print(f"average power (mW): {average_power*1000:.3f}")
-
-
-def approximate_watt(df: pd.DataFrame, resolution: float):
-    ratio = df["watt"] / resolution
-    df["watt_adjusted"] = resolution * np.round(ratio)
-    return df
-
-
-def draw_graph():
-    cap_sizes = [50, 100, 220, 470, 1000]
-    merged_dfs = []
-    for cap_size_uF in cap_sizes:
-        with open(f"output/result_{cap_size_uF}_uF.pickle", "rb") as f:
-            expr_results = pickle.load(f)
-        
-        dfs = []
-        for i, expr_result in enumerate(expr_results):
-            df_smu = expr_result["smu_result"]
-            df_scope = expr_result["scope_result"]
-            df = merge_and_analyze_df(df_smu, df_scope)
-            df["run_id"] = i
-            dfs.append(df)
-
-        df = pd.concat(dfs).reset_index(drop=True)
-        df = approximate_watt(df, 0.001)
-        df["cap_size_uF"] = cap_size_uF
-        merged_dfs.append(df)
-    
-    df = pd.concat(merged_dfs).reset_index()
-    print(df)
-
-    # plot_utils.set_theme_seaborn(kind="line")
-
-    watt_filter = [0.001, 0.002, 0.003, 0.005, 0.010]
-    df = df[np.isin(df["watt_adjusted"], watt_filter)]
-    g = sns.lineplot(
-        df,
-        x = "cap_size_uF",
-        y = "time_per_energy",
-        hue = "watt_adjusted",
-    )
-    return g
-
-    # g = sns.lineplot(
-    #     df_scope,
-    #     x="timestamp",
-    #     y="eps_on",
-    # )
-    # sns.lineplot(
-    #     df_scope,
-    #     x="timestamp",
-    #     y="in_execution",
-    #     linestyle="--",
-    #     color="cornflowerblue",
-    # )

+ 0 - 189
imc/exprs/dac2025/4_energy_efficiency/run_expr_4.py

@@ -1,189 +0,0 @@
-import tempfile
-import time
-import pickle
-import pandas as pd
-import threading
-import datetime
-
-from imc_utils.pps_e36311a import PPS_E36311A
-from imc_utils.smu_b2902a import SMU_B2902A
-from imc_utils.build_config.cortex_m33 import BuildConfigM33
-from imc_utils.build_config.test_env import TestEnv
-from imc_utils.serial_watch import SerialWatcher
-from imc_utils.oscilloscope_dsox1204a import DSOX1204A
-
-import imc_utils.serial_device
-
-WORKSPACE_ROOT = "/home/ybkim/workspace/imc/imc_freertos_app_m33"
-NVM_RESET_BIN = f"{WORKSPACE_ROOT}/imc/utils/nvm_reset.elf"
-OPENOCD_SCRIPT = f"{WORKSPACE_ROOT}/imc_freertos_app_m33.cfg"
-
-def set_current_limit_thread(current_limits, interval_sec, smu: SMU_B2902A):
-    for limit in current_limits:
-        # smu_busy = smu.smu.ask("*OPC?")
-        # print(smu_busy)
-        smu.smu.write("*WAI")
-        print(f"set current limit to: {limit*1000:.3f}mA")
-        smu.set_current_limit(limit)
-        time.sleep(interval_sec)
-
-def get_sampling_duration(curr_limit):
-    ratio = 0.020 / curr_limit
-    return 10 * ratio
-
-def get_scope_timebase(cap_size_uF):
-    d = {
-        1000: 3,
-        470: 2,
-        220: 1,
-        100: 0.8,
-        50: 0.5,
-    }
-    return d[cap_size_uF]
-
-def get_smu_sample_freq(cap_size_uF):
-    d = {
-        1000: 1000,
-        470: 1000,
-        220: 1000,
-        100: 2000,
-        50: 2000,
-    }
-    return d[cap_size_uF]
-
-def main():
-    volt = 1.5
-    cap_size_uF = 1000
-    smu_sample_freq = get_smu_sample_freq(cap_size_uF)
-    smu = SMU_B2902A(voltage=volt, sample_freq=smu_sample_freq)
-    smu.setup_sense()
-
-    config = get_default_build_config()
-
-    scope = DSOX1204A()
-
-    timebase = get_scope_timebase(cap_size_uF)
-    scope.set_volt_scale(3, 1)
-    scope.set_timebase(timebase)
-    scope.set_timebase_reference_left()
-    scope.set_trigger_falling_edge(3, 2)
-    scope.set_acquisition_type("hresolution")
-
-    benchmark = "vFFT"
-
-    current_limits = [ 0.001*i for i in range(20,0,-1)]
-    # current_limits = []
-    current_limits += [0.0005]
-    # current_limits = [0.01, 0.005, 0.001]
-
-    config.bench_name = benchmark
-
-    smu.set_current_limit(0.1)
-    smu.power_on()
-
-    env = TestEnv(WORKSPACE_ROOT, NVM_RESET_BIN, OPENOCD_SCRIPT)
-
-    with tempfile.TemporaryDirectory() as build_dir:
-        binary = env.build_binary(config, build_dir)
-        env.clear_nvm_and_load_binary(binary, resume=False)
-
-
-    smu.power_on()
-    smu.set_current_limit(current_limits[0])
-    startup_time = 10
-    print(f"wait for startup ({startup_time}s)")
-    time.sleep(startup_time)
-
-    interval = get_sampling_duration(current_limits[0])
-    # t = threading.Thread(target=set_current_limit_thread, args=(current_limits, interval, smu))
-    # t.start()
-
-    results = []
-    i = 0
-    current_limit_index = 0
-    start = datetime.datetime.now()
-
-    while True:
-        print(f"({i}) Start waiting for trigger")
-        scope.aquire_single()
-        smu.start_measure()
-
-        scope.wait_aquire_finish()
-        smu.stop_measure_only()
-        print(f"({i}) Finish measurement")
-
-        in_execution = scope.get_waveform(2)
-        eps_on = scope.get_waveform(3)
-        x_increment = scope.get_xincrement()
-
-        d = {
-            "in_execution": in_execution,
-            "eps_on": eps_on,
-            "timestamp": [i * x_increment for i in range(len(in_execution))],
-        }
-        scope_results = pd.DataFrame(d)
-
-        print(f"Sampled {len(scope_results)} points from the scope")
-
-        currs = smu.fetch_curr()
-        volts = smu.fetch_volt()
-        timestamps = smu.fetch_time()
-
-        d = {
-            "curr": currs,
-            "volt": volts,
-            "timestamp": timestamps
-        }
-
-        smu_results = pd.DataFrame(d)
-        print(f"Sampled {len(smu_results)} point from the smu")
-
-        results.append({
-            "scope_result": scope_results,
-            "smu_result": smu_results,
-        })
-
-        i += 1
-        now = datetime.datetime.now()
-        time_elapsed = now - start
-        print(time_elapsed)
-        if time_elapsed > datetime.timedelta(seconds=interval):
-            if current_limit_index == len(current_limits)-1:
-                break
-            current_limit_index += 1
-            current_limit = current_limits[current_limit_index]
-            print(f"set current limit to {current_limit*1000:.3f}mA")
-            interval = get_sampling_duration(current_limit)
-            print(f"set sampling duration: {interval:.3f}s")
-            smu.set_current_limit(current_limit)
-            start = now
-        
-
-    save_records(f"result_{cap_size_uF}_uF", results)
-    smu.power_off()
-
-
-def get_default_build_config():
-    config = BuildConfigM33()
-    config.insert_compiler_checkpoints = False
-    config.enable_extension = True
-    config.use_checkpoint_pass_counter = False
-    config.use_checkpoint_voltage_check = False
-    config.bench_infinite_loop = True
-    config.print_recovery_message = False
-    config.split_loop = False
-    config.enable_static_loop_pass_count = False
-    config.enable_adaptive_loop_pass_count = False
-    config.print_stats = False
-    config.custom_unroll = False
-    config.loop_opt_debug = False
-    return config
-
-
-def save_records(bench_name, df):
-    with open(f"output/{bench_name}.pickle", "wb") as f:
-        pickle.dump(df, f)
-
-
-if __name__ == "__main__":
-    main()

+ 0 - 55
imc/exprs/dac2025/build_and_program.py

@@ -1,55 +0,0 @@
-import tempfile
-import time
-import pickle
-import pandas as pd
-import threading
-import datetime
-
-from imc_utils.pps_e36311a import PPS_E36311A
-from imc_utils.smu_b2902a import SMU_B2902A
-from imc_utils.build_config.cortex_m33 import BuildConfigM33
-from imc_utils.build_config.test_env import TestEnv
-from imc_utils.serial_watch import SerialWatcher
-from imc_utils.oscilloscope_dsox1204a import DSOX1204A
-
-import imc_utils.serial_device
-
-WORKSPACE_ROOT = "/home/ybkim/workspace/imc/imc_freertos_app_m33"
-NVM_RESET_BIN = f"{WORKSPACE_ROOT}/imc/utils/nvm_reset.elf"
-OPENOCD_SCRIPT = f"{WORKSPACE_ROOT}/imc_freertos_app_m33.cfg"
-
-def main():
-    volt = 3.3
-    smu = SMU_B2902A(voltage=volt)
-
-    benchmark = "vrefint_expr"
-
-    config = BuildConfigM33()
-    config.insert_compiler_checkpoints = False
-    config.enable_extension = True
-    config.use_checkpoint_pass_counter = False
-    config.use_checkpoint_voltage_check = False
-    config.bench_infinite_loop = True
-    config.print_recovery_message = False
-    config.split_loop = False
-    config.enable_static_loop_pass_count = False
-    config.enable_adaptive_loop_pass_count = False
-    config.print_stats = False
-    config.custom_unroll = False
-    config.loop_opt_debug = False
-    config.bench_name = benchmark
-
-    smu.set_current_limit(0.1)
-    smu.power_on()
-
-    env = TestEnv(WORKSPACE_ROOT, NVM_RESET_BIN, OPENOCD_SCRIPT)
-
-    with tempfile.TemporaryDirectory() as build_dir:
-        binary = env.build_binary(config, build_dir)
-        env.clear_nvm_and_load_binary(binary, resume=True)
-
-    smu.power_off()
-
-
-if __name__ == "__main__":
-    main()

+ 0 - 5
imc/exprs/dac2025/set_smu_current.py

@@ -1,5 +0,0 @@
-from imc_utils.smu_b2902a import SMU_B2902A
-
-smu = SMU_B2902A(voltage=1.5)
-smu.set_current_limit(0.020)
-smu.power_on()

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików