ekalda commented on code in PR #16523:
URL: https://github.com/apache/tvm/pull/16523#discussion_r1481332421


##########
include/tvm/runtime/data_type.h:
##########
@@ -114,17 +118,28 @@ class DataType {
   /*! \return whether type is a handle type. */
   bool is_handle() const { return code() == DataType::kHandle && !is_void(); }
   /*! \return whether type is a vector type. */
-  bool is_vector() const { return lanes() > 1; }
+  bool is_vector() const {
+    int encoded_lanes = static_cast<int16_t>(data_.lanes);
+    return encoded_lanes != 0 && encoded_lanes != 1;
+  }
   /*! \return whether type is a bool vector type. */
   bool is_vector_bool() const { return is_vector() && bits() == 1; }
   /*! \return whether type is a Void type. */
   bool is_void() const { return code() == DataType::kHandle && bits() == 0 && 
lanes() == 0; }
+  /*! \return Whether the type is scalable. */
+  bool is_scalable() const { return static_cast<int16_t>(data_.lanes) < 0; }
   /*!
    * \brief Create a new data type by change lanes to a specified value.
    * \param lanes The target number of lanes.
    * \return the result type.
    */
   DataType with_lanes(int lanes) const { return DataType(data_.code, 
data_.bits, lanes); }
+  /*!
+   * \brief Create a new scalable data type by changing the lanes to a 
specified value.
+   * \param lanes The target number of lanes.

Review Comment:
   Thanks @tqchen, thinking about it, you're right, the "lanes" of the scalable 
vectors in the current implementation is a bit of a misnomer and in general 
causes a lot of issues where the scalability is silently ignored or dropped in 
the passes. So I'm in favour of separating the APIs for fixed length and 
scalable vectors. Here's a proposal for cleaning it up (it should address your 
other comments in this file as well):
   
   * Rename `is_scalable()` -> `is_scalable_vector()` - return `True` if it is 
scalable vector, `False` otherwise
   * Add `is_fixed_length_vector()` method to check if it is a fixed length 
vector
   * `is_vector()` should return `True` if it is a vector (scalable or fixed 
length) and `False` otherwise
   * Reserve `lanes()` for fixed length vectors, i.e. if this function is 
called on a scalable vector, return an error
   * Add `vscale_factor()` that returns the integer multiplier (so it would be 
a scalable vector equivalent of `lanes()`)
   * Rename `with_scalable_lanes(lanes)` -> 
`with_scalable_vscale_factor(vscale_factor)`
   
   
   Throughout the codebase `dtype.lanes() != 1` is used as a shorthand to test 
for "vectorness", it would be good to replace these instances with 
`is_vector()`/`is_fixed_length_vector()`/`is_scalable_vector()` as appropriate.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to