使用机读 AMD GPU ISA 规范解码指令

最初发布时间:
最后更新时间:
Amit Ben-Moshe's avatar
Amit Ben-Moshe
Nursultan Kabylkas's avatar
Nursultan Kabylkas

我们最近发布了 GPU 指令集架构 (ISA) 的机器可读规范,提供了一系列 XML 文件,详细介绍了 RDNA™ 和 CDNA™ 指令集架构。虽然您可以使用 XML 架构文档手动解析这些文件,但最简单的入门方法是使用 IsaDecoder API。此 API 读取和解析 XML 文件,并能够以二进制和文本格式解码单个指令或整个内核。

这是一个简单的程序,演示了使用 API 解码单个 MI-300/CDNA™ 3 指令有多么容易。该程序从硬编码路径加载规范 XML 文件,并解码硬编码指令 (0x7e000301)。

int main()
{
// Initialize the decoder with the MI300/CDNA3 XML ISA specification file.
amdisa::IsaDecoder decoder;
const char* kPathToSpec = "path/to/xml/spec/amdgpu_isa_mi300.xml";
std::string error_msg;
bool is_initialized = decoder.Initialize(kPathToSpec, error_msg);
if (is_initialized)
{
// Decode instruction 0x7e000301.
amdisa::InstructionInfoBundle inst_bundle;
bool is_decoded = decoder.DecodeInstruction(0x7e000301, inst_bundle, error_msg);
if (is_decoded)
{
for (const amdisa::InstructionInfo& inst : inst_bundle.bundle)
{
std::cout << "Instruction Name: " << inst.instruction_name << std::endl;
std::cout << "Instruction Description: " << inst.instruction_description << std::endl;
// More information is available in the InstructionInfo structure,
// such as operands and their type (input/output/SGPR/VGPR/etc.), flags and more.
}
}
else
{
std::cerr << error_msg << std::endl;
}
}
else
{
std::cerr << error_msg << std::endl;
}
return 0;
}

解码后,程序将输出指令名称以及从解码的 InstructionInfo 结构中获取的可读指令描述。

终端窗口
Instruction Name: V_MOV_B32
Instruction Description: Move 32-bit data from a vector input into a vector register.

填充的 InstructionInfo 结构包含有关解码指令的详细信息,如其编码、操作数及其类型(输入/输出/SGPR/VGPR 等)以及标志。有关可用信息的完整描述,请参阅GitHub上的 API 文档。

此外,如上所述,该 API 不仅限于解码单个指令——它还可以用于解码二进制和反汇编格式的整个内核和着色器。API 用法示例和更多详细信息可在 GitHub 上的isa_spec_manager 存储库中找到,其中包含 API 源代码——快来看看吧!

您也可以在此处的 GPUOpen 上的AMD 机器可读 ISA 规范页面上找到更多信息!

Amit Ben-Moshe's avatar

Amit Ben-Moshe

Amit Ben-Moshe 是 AMD 的杰出工程师。他的发帖内容代表他个人的观点,可能不代表 AMD 的立场、策略或观点。第三方网站链接仅为方便起见提供,除非明确说明,否则 AMD 对这些链接网站的内容概不负责,也不暗示任何认可。
Nursultan Kabylkas's avatar

Nursultan Kabylkas

Nursultan Kabylkas 博士(计算机工程博士)是 AMD GPU 机器可读 ISA 规范项目的高级软件工程师。

相关新闻和技术文章

相关视频

© . This site is unofficial and not affiliated with AMD.