Get an access pointer to the head of buffer. This is the recommended method to get buffer data ptress when interacting with external functions. Parameters ---------- access_mask : int The access pattern MASK. Indicate whether the acce
(self, access_mask, ptr_type="handle", content_lanes=1, offset=0, extent=None)
| 47 | WRITE = 2 |
| 48 | |
| 49 | def access_ptr(self, access_mask, ptr_type="handle", content_lanes=1, offset=0, extent=None): |
| 50 | """Get an access pointer to the head of buffer. |
| 51 | |
| 52 | This is the recommended method to get buffer data |
| 53 | ptress when interacting with external functions. |
| 54 | |
| 55 | Parameters |
| 56 | ---------- |
| 57 | access_mask : int |
| 58 | The access pattern MASK. Indicate whether the |
| 59 | access will read or write to the data content. |
| 60 | |
| 61 | ptr_type : str, optional |
| 62 | The data type of the result pointer. Do not specify |
| 63 | unless we want to cast pointer to specific type. |
| 64 | |
| 65 | content_lanes: int, optional |
| 66 | The number of lanes for the data type. This value |
| 67 | is greater than one for vector types. |
| 68 | |
| 69 | offset: Expr, optional |
| 70 | The offset of pointer. We can use it to offset by |
| 71 | the number of elements from the address of ptr. |
| 72 | |
| 73 | extent: Expr, optional |
| 74 | The extent of pointer. |
| 75 | |
| 76 | Examples |
| 77 | -------- |
| 78 | .. code-block:: python |
| 79 | |
| 80 | # Get access ptr for read |
| 81 | buffer.access_ptr("r") |
| 82 | # Get access ptr for read/write with bitmask |
| 83 | buffer.access_ptr(Buffer.READ | Buffer.WRITE) |
| 84 | # Get access ptr for read/write with str flag |
| 85 | buffer.access_ptr("rw") |
| 86 | # Get access ptr for read with offset |
| 87 | buffer.access_ptr("r", offset = 100) |
| 88 | # Get access ptr for read with extent |
| 89 | buffer.access_ptr("r", extent = 100) |
| 90 | """ |
| 91 | if isinstance(access_mask, str): |
| 92 | mask = 0 |
| 93 | for value in access_mask: |
| 94 | if value == "r": |
| 95 | mask = mask | Buffer.READ |
| 96 | elif value == "w": |
| 97 | mask = mask | Buffer.WRITE |
| 98 | else: |
| 99 | raise ValueError(f"Unknown access_mask {access_mask}") |
| 100 | access_mask = mask |
| 101 | offset = convert(offset) |
| 102 | extent = convert(extent) |
| 103 | return _ffi_api.BufferAccessPtr( |
| 104 | self, |
| 105 | access_mask, |
| 106 | ptr_type, |