This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

What is int_width about in arm_nn_activations_direct_q7 about

Hi all,

recently, I am trying to implement neural networks on one of my Cortex-M devices. However, I wasn't know what "int_width" in arm_nn_activations_direct_q7 is about. The definition in the document is: "bit-width of the integer part, assume to be smaller than 3" but it is still unclear to me. Please give me some example about it as I am trying to transfer neural networks from other DL framework like tensorflow and pytorch. Many thanks!!

Parents
  • They define q7_t as a signed 8-bit integer to represent a "fractional data type in 1.7 format". Assuming that Arm is using the AMD variant of the definition of a Q number, a q7_t is a fraction in the range [-1.0, 1), i.e. 1 sign bit, no integer bit, and 7 fractional bits. They seem to have repurposed the same data type q7_t to represent fractions with 1, 2 or 3 integer bits at the cost of reducing the number of fractional bits.

    The tables that they have prepared take an input in the range [-8.0, 8.0). By selecting the int_width value, you are informing the library of the range of your input.

    For e.g., the number 0x80 is -1.0 in q1.7 fraction, but it is -8.0 in q4.4 fraction. When your input assumes an int_width of 0, so that 0x80 represents -1.0, the library needs to locate -1.0 in its range [-8.0, 8.0). It cannot directly use 0x80 as -1.0, since the table assumes that its input is in q4.4 format, and 0x80 in q4.4 is -8.0, not -1.0. The right-shift converts from q1.7 (or q2.6, q3.5, q4.4, based on int_width) to q4.4.

Reply
  • They define q7_t as a signed 8-bit integer to represent a "fractional data type in 1.7 format". Assuming that Arm is using the AMD variant of the definition of a Q number, a q7_t is a fraction in the range [-1.0, 1), i.e. 1 sign bit, no integer bit, and 7 fractional bits. They seem to have repurposed the same data type q7_t to represent fractions with 1, 2 or 3 integer bits at the cost of reducing the number of fractional bits.

    The tables that they have prepared take an input in the range [-8.0, 8.0). By selecting the int_width value, you are informing the library of the range of your input.

    For e.g., the number 0x80 is -1.0 in q1.7 fraction, but it is -8.0 in q4.4 fraction. When your input assumes an int_width of 0, so that 0x80 represents -1.0, the library needs to locate -1.0 in its range [-8.0, 8.0). It cannot directly use 0x80 as -1.0, since the table assumes that its input is in q4.4 format, and 0x80 in q4.4 is -8.0, not -1.0. The right-shift converts from q1.7 (or q2.6, q3.5, q4.4, based on int_width) to q4.4.

Children