tenstorrent / sfpi

Apache License 2.0
3 stars 0 forks source link

crash w/ function argument passed into conditional #7

Open pgkeller opened 4 months ago

pgkeller commented 4 months ago

The code below:

template <bool APPROXIMATION_MODE>
inline void calculate_softplus_body(vFloat beta, vFloat beta_reciprocal, vFloat threshold) {
    vFloat a = dst_reg[0];
    vFloat a_beta = a * beta;
    v_if(a_beta < threshold) {
        exp_init<APPROXIMATION_MODE>();
        a = calculate_exponential_body<APPROXIMATION_MODE>(a_beta) + 1.0f;

        dst_reg[0] = a;
        _calculate_log_body_<false>(0);
        a = beta_reciprocal * dst_reg[0];
    }
    v_endif;
    dst_reg[0] = a;
}

generates:

Illegal rvtt builtin found in conditional tree: sfpxloadi
during GIMPLE pass: rvtt_expand
/localdev/esmal/tt-metal/tt_metal/hw/ckernels/grayskull/metal/llk_api/llk_sfpu/ckernel_sfpu_softplus.h: In function 'calculate_softplus_body.constprop.isra':
/localdev/esmal/tt-metal/tt_metal/hw/ckernels/grayskull/metal/llk_api/llk_sfpu/ckernel_sfpu_softplus.h:39:13: internal compiler error: in process_tree_node, at gimple-rvtt-expand.c:622
   39 | inline void calculate_softplus_body(vFloat beta, vFloat beta_reciprocal, vFloat threshold) {
      |             ^
0x7f607ab8b082 __libc_start_main
        ../csu/libc-start.c:308

My guess is that the fn is not inlined and that the check for the conditional happens before the error checking that the value isn't loaded from memory - we should error out w/ "can't load sfpu vector from memory" but instead we crash. Needs a little investigation

nathan-TT commented 2 months ago

Is there a complete test case -- not just a code fragment? An what compilation options?

pgkeller commented 2 months ago

Is there a complete test case -- not just a code fragment? An what compilation options?

No complete test case. I'd try to repro in a test like the ones in the sfpi tests (same args), should happen w/ any arch.