Translation of CUDA inline asm from GAS to Intel

时间:2019-04-17 01:40:02

标签: c linux windows cuda inline-assembly

I have some C-CUDA code that contains inline PTX assembly, which compiles OK on Linux with g++ backend.

I need to build it under Windows, and clearly MSVC backend does not recognize inline asm properly - gives errors like "not an asm string". I assume it has to do with syntax this PTX assembly is written, for example:

    asm volatile ("subc.cc.u32 %0, %0, "q2_s";": "+r"(c[2]));
    asm volatile ("subc.cc.u32 %0, %0, "q3_s";": "+r"(c[3]));

I don't know much about assembly, and am wondering - is there some translator from GAS(at&t) style to Intel syntax?

Or is there some workaround to build CUDA kernels to PTX on Linux, and then build PTX & link to remaining code on Windows? I've tried that, but PTX compiler on linux gives kernel functions some unrecognizable _Z-starting names and linker does not know how to link the stuff.

1 个答案:

答案 0 :(得分:1)

结果证明,问题不是内联汇编,而是预处理,例如例如asm字符串

asm volatile ("subc.cc.u32 %0, %0, "q2_s";": "+r"(c[2]));

依赖于此定义

#define q2_s "0xAF48A03B"

在Linux上,编译时没有错误,但是在Windows上,出现了“预期的asm字符串”错误。 因此,Windows的解决方法只是将asm字符串中的十六进制值硬编码,并且与汇编语法无关,抱歉。