0

Consider the following PTX code:

//
// Generated by NVIDIA NVVM Compiler... sort of
//
// Compiler Build ID: CL-25769353
// Cuda compilation tools, release 10.1, V10.1.105
// Based on LLVM 3.4svn
//

.version 6.4
.target sm_30
.address_size 64

.func  (.param .b32 func_retval0) foo(
        .param .b32 foo_param_0,
        .param .b32 foo_param_1,
        .param .b32 foo_param_2
)
{
        .reg .b16       %rs<3>;
        .reg .b32       %r<3>;


        ld.param.u16    %rs1, [foo_param_0];
        ld.param.u16    %rs2, [foo_param_1];
        ld.param.u32    %r2, [foo_param_2];
        // inline asm
        sad.s16 %r1, %rs1, %rs2, %r2;
        // inline asm
        st.param.b32    [func_retval0+0], %r1;
        ret;
}

When trying to compile this with ptxas (CUDA 10.1), I get:

ptxas /tmp/a.ptx, line 27; error   : Arguments mismatch for instruction 'sad'
ptxas fatal   : Ptx assembly aborted due to errors

why is that? What's wrong with this combination of types?

The PTX reference says:

sad.type  d, a, b, c;

.type = { .u16, .u32, .u64,
          .s16, .s32, .s64 };

and it seems d and c are u32 always and type applies to a and b. That's what the __sad() functions in device_functions.h have anyway.

einpoklum
  • 118,144
  • 57
  • 340
  • 684

1 Answers1

1

Actually, the type of d and a needs to be "the unsigned version of the type of b and c". So, this should work:

.func  (.param .b32 func_retval0) foo(
        .param .b32 foo_param_0,
        .param .b32 foo_param_1,
        .param .b32 foo_param_2
)
{
        .reg .b32       %r<5>;


        ld.param.u32    %r4, [foo_param_2];
        ld.param.s16    %r2, [foo_param_0];
        ld.param.s16    %r3, [foo_param_1];
        // inline asm
        sad.s32 %r1, %r2, %r3, %r4;
        // inline asm
        st.param.b32    [func_retval0+0], %r1;
        ret;
}
einpoklum
  • 118,144
  • 57
  • 340
  • 684