Skip to content

This project is a radiation effects simulator for RRAM-based analog compute-in-memory (CIM) systems.

Notifications You must be signed in to change notification settings

Tsinghua-LEMON-Lab/RESCIM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RESCIM

​ 本项目为面向 RRAM 模拟存算一体系统(ACIM)的辐照特性仿真器。模型考虑了多种非理想因素对于 CNN 推理精度造成的影响。

非理想因素建模

​ 电路和器件的非理想因素主要在 RESCIM\radiation_model\r_model_torch.py 文件的 Macro_MVM_1bIN_4bOUT_SIM 函数中进行建模。目前考虑的非理想因素已经相应的建模方式包括:

  1. **DAC 转换误差:**在输出模拟信号上加入高斯噪声($3\sigma$限幅)建模模拟信号真实值与理论值之间存在的随机误差。噪声标准差大小由参数 DAC_noise 控制,其表示噪声相对于输入电平的幅度,如5%。

  2. **器件电导值误差:**由于器件的非理想因素,各个器件体现的实际电导值与预期值存在误差,用加性限幅高斯噪声建模。误差标准差由参数 conductance_noise 控制,其为误差电导相对于忆阻器最大电导的比例,如5%。此外,可设置一定比例的忆阻器单元产生固定比例的漂移,比例由 cell_conductance_offset_rate 控制,偏移幅度由 cell_conductance_offset 控制, 如10%,-5%等。

  3. **器件损坏误差:**由于良率或极端条件影响,部分器件可能出现永久性损坏。目前简单建模了器件开路和短路两种情况,分别对应0电导和最大电导。器件开路和短路率分别由参数 cell_open_ratecell_short_rate 控制。此外,可以将一定比例的忆阻器电导设定为特定值(不超过忆阻器可表示的电导范围),比例由cell_fixed_conductance_rate 控制,设置的固定电导值为 cell_fixed_conductance。忆阻器电导绝对值的最大值默认为 19.16 (单位为 $\mu S$)。

  4. **ADC 转换误差:**可以用增益误差、失调误差、积分非线性误差3个细化指标表述 ADC 转换误差,每个误差用高斯噪声建模,用参数 ADC_sigma_gain_errorADC_sigma_offset_errorADC_sigma_inl_error 分别控制 3 个高斯噪声的标准差。其中 ADC_sigma_offset_errorADC_sigma_inl_error 的单位是 LSB(ADC的最小量化间隔), ADC_sigma_gain_error 表示相对于理想 ADC 转换斜率(为1)的偏差,如2%。

  5. **ADC噪声:**用一个高斯噪声简化 4 的建模, 用 ADC_noise控制噪声标准差,相对于最大输出电流。

  6. **ADC量化比特错误:**ADC量化后的数字激活值有小概率发生比特翻转。

  7. DAC 和 ADC 的量化误差:在量化过程中自然携带,无需单独建模。

使用方法

环境配置

选择合适环境(如新建一个 RESCIM 环境,以下在该环境下操作)

前往 PyTorch 官网 根据自己设备的配置下载带有 cuda 支持的 torch,如

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126

下载其他包:

pip install numpy onnx onnxruntime onnxsim matplotlib pillow scikit-learn scikit-opt pyyaml opencv-python tqdm

下载 OPEMCIMTC 编译器本地包:

git clone git@github.com:Tsinghua-LEMON-Lab/OpenCIMTC.git
cd OpenCIMTC
pip install -e .

下载 RESCIM 仿真器本地包:

git clone git@github.com:lbqy/RESCIM.git
cd RESCIM
pip install -e .

命令行界面 (CLI)

ResNet32

可设置参数:

    p.add_argument('-i', '--input_data', default=None, help='the validating input data for the model')
    p.add_argument('-t', '--target_data', default=None, help='the validating target data for the model')
    p.add_argument('-w', '--weight_data', default=None, help='the trained weight data of the model')
    p.add_argument('-WN', '--weight_noise', default=0, type=float, help='Relative conductance noise amplitude')
    p.add_argument('-DN', '--DAC_noise', default=0, type=float, help='DAC noise amplitude')
    p.add_argument('-CCOR', '--cell_conductance_offset_rate', default=0, type=float, help='rate of the cells with conductance offset')
    p.add_argument('-CCO', '--cell_conductance_offset', default=0, type=float, help='cell conductance offset')
    p.add_argument('-CO', '--cell_open_rate', default=0, type=float, help='cell open rate')
    p.add_argument('-CS', '--cell_short_rate', default=0, type=float, help='cell short rate')
    p.add_argument('-CFCR', '--cell_fixed_conductance_rate', default=0, type=float, help='rate of the cells with fixed conductance')
    p.add_argument('-CFC', '--cell_fixed_conductance', default=0, type=float, help='fixed conductance of the cells')
    p.add_argument('-AN', '--ADC_noise', default=0, type=float, help='ADC noise amplitude')
    p.add_argument('-AO', '--ADC_sigma_offset_error', default=0, type=float, help='ADC offset error')
    p.add_argument('-AG', '--ADC_sigma_gain_error', default=0, type=float, help='ADC gain error')
    p.add_argument('-AI', '--ADC_sigma_inl_error', default=0, type=float, help='ADC inl error')
    p.add_argument('-AB', '--ADC_bit_error_rate', default=0, type=float, help='ADC bit error')
    p.add_argument('-device', '--device', default='cuda', help='simulation platform, cuda or cpu')
    p.add_argument('-n', '--simulation_times', default=10, type=int, help='Times of simulation')

命令示例:

python test/sim.py -o test/model/resnet32.onnx -i test/dataset/cifar1000.pth -t test/dataset/batch_targets1000.pth -w test/model/resnet32_mapped_ir_PDT_best.pth -WN 0.06

YOLOv4-tiny

数据集准备:Dataset link: https://pan.baidu.com/s/19Mw2u_df_nBzsC2lg20fQA, Password: j5ge,下载后将VOCdevikit 文件夹移入 test\yolov4_tiny 目录下。

可设置的参数:

    p.add_argument('-IN', '--number_of_images', default=100, type=int, help='The number of evaluation images')
    p.add_argument('-WN', '--weight_noise', default=0, type=float, help='Relative conductance noise amplitude')
    p.add_argument('-DN', '--DAC_noise', default=0, type=float, help='DAC noise amplitude')
    p.add_argument('-CCOR', '--cell_conductance_offset_rate', default=0, type=float, help='rate of the cells with conductance offset')
    p.add_argument('-CCO', '--cell_conductance_offset', default=0, type=float, help='cell conductance offset')
    p.add_argument('-CO', '--cell_open_rate', default=0, type=float, help='cell open rate')
    p.add_argument('-CS', '--cell_short_rate', default=0, type=float, help='cell short rate')
    p.add_argument('-CFCR', '--cell_fixed_conductance_rate', default=0, type=float, help='rate of the cells with fixed conductance')
    p.add_argument('-CFC', '--cell_fixed_conductance', default=0, type=float, help='fixed conductance of the cells')
    p.add_argument('-AN', '--ADC_noise', default=0, type=float, help='ADC noise amplitude')
    p.add_argument('-AO', '--ADC_offset_error_sigma', default=0, type=float, help='ADC offset error')
    p.add_argument('-AG', '--ADC_gain_error_sigma', default=0, type=float, help='ADC gain error')
    p.add_argument('-AI', '--ADC_inl_error_sigma', default=0, type=float, help='ADC inl error')
    p.add_argument('-AB', '--ADC_bit_error_rate', default=0, type=float, help='ADC bit error')
    p.add_argument('-device', '--device', default='cuda', type=str, help='simulation platform, cuda or cpu')

命令示例:

python test/yolov4_tiny/get_map_rescim.py -IN 200 -WN 0.6 -device 'cuda'

About

This project is a radiation effects simulator for RRAM-based analog compute-in-memory (CIM) systems.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages