If you are passing CuPy coordinates from a native Python operator to Holoviz, if you run into the error [2023-02-28 00:34:25.313] [holoscan] [error] [gxf_wrapper.cpp:68] Exception occurred for operator: 'holoviz' - size should not be zero
while trying to render texts in Holoviz, or other errors while rendering other types in Holoviz that indicates a discrepancy in the array values passed from the native Python operator and the array values received by Holoviz, then it may be due to an existing CuPy issue Unexpected stride when performing cupy.asarray on numpy.ndarray with leading dim 1 · Issue #5897 · cupy/cupy · GitHub. This issue affects any CuPy arrays that have leading dimension 1 when calling astype
or cp.array
.
For example, when defining a label_coords
that the native Python operator outputs via
out_message.add(hs.as_tensor(label_coords), "label_coords")
op_output.emit(out_message, "outputs")
the following works without error
label_coords = cp.array([0.1, 0.1, .1], dtype=cp.float32).reshape((1, 1, 3))
label_coords = cp.array([0.1, 0.1, .1], dtype=cp.float32).reshape((1, 1, 3)).astype(cp.float32, copy=False)
# just for experimenting:
label_coords = cp.array([0.1, 0.1, .1], dtype=cp.float32).reshape((1, 1, 3)).copy()
label_coords = cp.array([0.1, 0.1, .1], dtype=cp.float32).reshape((1, 1, 3)).copy().astype(cp.float32, copy=False).copy()
and the following will generate the error:
label_coords = cp.array([0.1, 0.1, .1], dtype=cp.float32).reshape((1, 1, 3)).astype(cp.float32)
label_coords = cp.array([0.1, 0.1, .1], dtype=cp.float32).reshape((1, 1, 3)).astype(cp.float32, copy=True)
If you need to call astype()
, a temporary workaround is to pass order='C'
to the astype()
call. This will work whether or not copy
is True or False.