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 Usage

Obtains the memory data pointer address of a numpy.ndarry array.

If the input numpy.ndarry array is non-contiguous in memory, convert the non-contiguous memory to contiguous one and then obtain the numpy.ndarry array after conversion and convert it to 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 is non-contiguous in the memory, the return value data_out is the NumPy array after the non-contiguous memory is converted into contiguous one.

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 passed numpy.ndarray object has not ended (has not been deleted or collected by Python's GC), otherwise undefined behavior may occur.