文档
注册

核函数CPU孪生调试

CPU孪生调试支持自动精度比对、仿真内存校验和异常检测(npucheck)等功能,全量功能和参数介绍参见CPU调测功能

本场景以AddCustom算子为例,通过torch生成输入数据和标杆数据,核函数CPU调测过程如下。请根据自身实际情况,按需修改示例代码。

import torch
import numpy as np
import ascendebug

# 设置和清理日志文件
ascendebug.set_log_file('test.log', clean=True)

# 1.生成输入/标杆数据
x = torch.rand(size=(1, 16384), dtype=torch.float16)
y = torch.rand(size=(1, 16384), dtype=torch.float16)
z = x + y

# 2.构建算子信
debug_op = ascendebug.create_debug_op('add_custom', 'VectorCore', 'Ascend310P') \
	.scalar_input('tileNumIn', 'uint32', 10) \
	.tensor_input('x', x) \
	.tensor_input('y', y) \
	.tensor_output('z', z)

# 3.创建调试对象并初始化工作空间
install_pkg = "/home/run_pkg/"
op_executor = ascendebug.create_op_executor(debug_op=debug_op, install_path=install_pkg)

# 4.配置核函数源码信息
kernel_info = ascendebug.OpKernelInfo("/src_path/add_custom.cpp", 'add_custom', [])

# 5.调用CPU编译运行接口,在CPU上仿真运行核函数,完成精度比对
cpu_option = ascendebug.CpuOptions()
op_executor.run_call_kernel_cpu(kernel_info, 32, cpu_option)

算子在CPU侧的孪生调试结果示例可以参见“CPU调测功能 > 调测产物”。

搜索结果
找到“0”个结果

当前产品无相关内容

未找到相关内容,请尝试其他搜索词