Skip to content

Conversation

@valerioedu
Copy link
Contributor

@valerioedu valerioedu commented May 11, 2025

  • Replaced literal cast 1.050700987… → res_T with a static const ap_fixed<16,2> lambda, preserving range and ~1.5 × 10⁻² LSB precision regardless of user-chosen res_T.
  • Removed redundant datareg scope; now a single per-element branch: if (x ≥ 0) y = λ · x
    else y = selu_table[idx] (with index clamped to [0,N-1]).
  • Guard against negative-index underflow; behaviour for <0 inputs unchanged.
  • Keeps identical latency/area on Vivado 2023.1 & Vitis 2024.1, but
    eliminates silent overflow/rounding when res_T is narrow (e.g., ap_fixed<8,2>).

Fixes #1287

* Replaced literal cast 1.050700987… → `res_T` with a
  `static const ap_fixed<16,6> lambda`, preserving range and
  ~1.5 × 10⁻² LSB precision regardless of user-chosen `res_T`.
* Removed redundant datareg scope; now a single per-element branch:
      if (x ≥ 0)  y = λ · x
      else        y = selu_table[idx]   (with index clamped to [0,N-1]).
* Guard against negative-index underflow; behaviour for <0 inputs unchanged.
* Keeps identical latency/area on Vivado 2023.1 & Vitis 2024.1, but
  eliminates silent overflow/rounding when `res_T` is narrow (e.g., ap_fixed<8,2>).

Fixes #1287
@vloncar
Copy link
Contributor

vloncar commented May 11, 2025

Why use 6 integer bits to represent "1.0507"?

@valerioedu
Copy link
Contributor Author

Why use 6 integer bits to represent "1.0507"?

Yeah, my bad. It was late and I must have confused with another project of mine. I'm updating it to use 2 integer bits.

@jmitrevs
Copy link
Contributor

One could also use ufixed since the value is positive, to not use a sign bit.

@jmitrevs
Copy link
Contributor

Can you also fix the pre-commit issue? (I think it's trailing whitespace)

}

typedef ap_fixed<16,2> selu_const_t; // ±512 range, ≈1.5e-2 LSB
typedef ap_ufixed<16,2> selu_const_t;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would just 1 integer bit be enough?

Copy link
Contributor Author

@valerioedu valerioedu May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, kept one more just to be sure, do you want me to bring it to 1?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 1 makes sense, since the number is in the range.

@jmitrevs
Copy link
Contributor

jmitrevs commented May 12, 2025

For pre-commit, add the pre-commit package to your python setup and do pre-commit run -a (I think). It should fix the issues (or tell you how to fix them).

@valerioedu
Copy link
Contributor Author

guys it still finds trailing whitespaces, but I can't find them, any suggestions?

@valerioedu valerioedu changed the title activation: use dedicated fixed-point λ for SeLU (fixes #1287) compare: May 12, 2025
@valerioedu valerioedu changed the title compare: activation: use dedicated fixed-point λ for SeLU (fixes #1287) May 12, 2025
@valerioedu
Copy link
Contributor Author

guys I'm opening a new PR since this one is getting messy

@jmitrevs
Copy link
Contributor

This is replaced by #1298 .

@jmitrevs jmitrevs closed this Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SeLU activation range?

3 participants