Function: numpy_contiguous_to_ptr

This API will be deprecated. Use acl.util.bytes_to_ptr instead.

C Prototype

None

Python Function

ptr, data_out = acl.util.numpy_contiguous_to_ptr(data_in)

Function Description

Obtains the memory data pointer address of the numpy.ndarray array.

If the input numpy.ndarray array is non-contiguous in the memory, the memory is converted into contiguous rows, and then the converted numpy.ndarray array is converted into the memory data pointer address.

Input Description

data_in: data of the NumPy type.

Return Value

ptr: int, data that can be accessed by the C language.

data_out: NumPy data. If the input NumPy array data_in memory is not continuous, the return value data_out is the NumPy array after the memory is converted into continuous lines.

Restrictions

If data of the int type is accessed, the memory data pointer address of the numpy.ndarray object needs to be converted to int.

Precautions

  • Example modification:
    np_ptr, data_out = acl.util.numpy_contiguous_to_ptr(np_arr_in)

    After modification:

    bytes_in = np_arr_in.tobytes()
    bytes_ptr = acl.util.bytes_to_ptr(bytes_in)
  • To continue to use this API, ensure that the operating environment uses Python 3.8 or later and NumPy 1.22.0 or later.
  • Before using the pointer address returned by this function, ensure that the lifecycle of the input numpy.ndarray object has not ended (not deleted or reclaimed by the GC of Python). Otherwise, undefined behavior will occur.