def make_behaving(ary, dtype=None):
    """ Make sure that `ary` is a "behaving" bohrium array of type `dtype`.

    Requirements for a behaving array:
     * Is a bohrium array
     * Points to the first element in the underlying base array (no offset)
     * Has the same total length as its base

    Parameters
    ----------
    ary : BhArray
        The array to make behaving
    dtype : boolean, optional
        The return array is converted to `dtype` if not None
    
    Returns
    -------
    A behaving BhArray that might be a copy of `ary`

    Note
    ----
    Use this function to make sure that operands given to `execute()` is "behaving" that is
    the kernel can access the arrays without worrying about offset and stride.
    """

    if ary.isbehaving():
        ret = ary
    else:
        ret = ary.flatten(always_copy=True)
    if dtype is not None:
        ret = ret.astype(dtype)
    return ret