[][src]Function onednn_sys::dnnl_memory_desc_reshape

pub unsafe extern "C" fn dnnl_memory_desc_reshape(
    out_memory_desc: *mut dnnl_memory_desc_t,
    in_memory_desc: *const dnnl_memory_desc_t,
    ndims: c_int,
    dims: *mut dnnl_dim_t
) -> dnnl_status_t

Initializes a memory descriptor by reshaping an existing one. The new memory descriptor inherits the data type. This operation is valid only for memory descriptors that have format_kind set to #dnnl_blocked or #dnnl_format_kind_any.

The operation ensures the transformation of the physical memory format corresponds to the transformation of the logical dimensions. If such transformation is impossible, the function returns #dnnl_invalid_arguments.

The reshape operation can be described as a combination of the following basic operations:

  1. Add a dimension of size 1. This is always possible.
  2. Remove a dimension of size 1. This is possible only if the dimension has no padding (i.e. padded_dims[dim] == dims[dim] && dims[dim] == 1).
  3. Split a dimension into multiple ones. This is possible only if the size of the dimension is exactly equal to the product of the split ones and the dimension does not have padding (i.e. padded_dims[dim] = dims[dim]).
  4. Joining multiple consecutive dimensions into a single one. As in the cases above, this requires that the dimensions do not have padding and that the memory format is such that in physical memory these dimensions are dense and have the same order as their logical counterparts. This also assumes that these dimensions are not blocked.
    • Here, dense means: stride for dim[i] == (stride for dim[i + 1]) * dim[i + 1];
    • And same order means: i < j if and only if stride for dim[j] <= stride for dim[i].

@warning Some combinations of physical memory layout and/or offsets or dimensions may result in a failure to make a reshape.

@param out_memory_desc Output memory descriptor. @param in_memory_desc An existing memory descriptor. Must have format_kind set to #dnnl_blocked or #dnnl_format_kind_any. @param ndims Number of dimensions for the output memory descriptor. @param dims Dimensions for the output memory descriptor. @returns #dnnl_success on success and a status describing the error otherwise.