|
25 | 25 | AtomicLoad, |
26 | 26 | AtomicStore, |
27 | 27 | LoadPointer, |
28 | | - ReinterpretPointerAsArray, |
29 | 28 | StorePointer, |
30 | 29 | ) |
31 | 30 | from cuda.lang._ir.type_checking_helpers import ( |
|
44 | 43 | uint64, |
45 | 44 | ) |
46 | 45 | from cuda.tile._ir.arithmetic_ops import astype, binary_arithmetic_tensorlike_raw |
47 | | -from cuda.tile._ir.cast_ops import address_space_cast, implicit_cast, reinterpret_pointer |
| 46 | +from cuda.tile._ir.cast_ops import address_space_cast, implicit_cast |
48 | 47 | from cuda.tile._ir.core_ops import bind_method, loosely_typed_const, strictly_typed_const |
49 | | -from cuda.tile._ir.ir import add_operation_variadic |
| 48 | +from cuda.tile._ir.ir import add_operation_variadic, make_aggregate |
50 | 49 | from cuda.tile._ir.op_impl import ( |
51 | 50 | ImplRegistry, |
52 | 51 | WILDCARD, |
@@ -460,39 +459,29 @@ def address_space_cast_impl(value: Var, memory_space: Var) -> Var: |
460 | 459 | return address_space_cast(value, memory_space) |
461 | 460 |
|
462 | 461 |
|
463 | | -@impl(core_api.reinterpret_pointer_as_array) |
464 | | -def reinterpret_pointer_as_array_impl(pointer: Var, dtype: Var, shape: Var, strides: Var) -> Var: |
465 | | - if not strides.is_constant() or strides.get_constant() is not None: |
466 | | - raise TypeCheckingError( |
467 | | - "Reinterpreting a pointer as an array with " |
468 | | - "non-default strides is not yet implemented." |
469 | | - ) |
470 | | - pointer_ty = require_pointer_type(pointer) |
| 462 | +@impl(Array.from_parts) |
| 463 | +def array_from_parts_impl(pointer: Var, shape: Var, strides: Var) -> Var: |
| 464 | + pointer_ty = require_concrete_pointer_type(pointer) |
471 | 465 | shape = require_constant_int_tuple(shape, allow_single_int=True) |
472 | | - dtype = require_dtype_spec(dtype) |
473 | | - strides = contiguous_strides_from_shape(shape) |
474 | | - memory_space = pointer_ty.memory_space |
475 | | - |
476 | | - typed_pointer_ty = PointerTy(pointer_dtype(dtype, memory_space)) |
477 | | - if pointer.get_type() != typed_pointer_ty: |
478 | | - pointer = reinterpret_pointer(pointer, typed_pointer_ty.pointer_dtype) |
| 466 | + if strides.is_constant() and strides.get_constant() is None: |
| 467 | + strides = contiguous_strides_from_shape(shape) |
| 468 | + else: |
| 469 | + strides = require_constant_int_tuple(strides, allow_single_int=True) |
| 470 | + if len(strides) != len(shape): |
| 471 | + raise TypeCheckingError( |
| 472 | + f"Shape and strides must have the same rank, got {len(shape)} and {len(strides)}" |
| 473 | + ) |
479 | 474 | index_dtype = datatype.int32 |
480 | 475 | array_ty = ArrayTy( |
481 | | - dtype, |
| 476 | + pointer_ty.pointee_dtype, |
482 | 477 | shape=shape, |
483 | 478 | strides=strides, |
484 | 479 | typing_hooks=pointer.ctx.typing_hooks, |
485 | 480 | index_dtype=index_dtype, |
486 | | - memory_space=memory_space, |
487 | | - ) |
488 | | - result = add_operation( |
489 | | - ReinterpretPointerAsArray, |
490 | | - array_ty, |
491 | | - pointer=pointer, |
| 481 | + memory_space=pointer_ty.memory_space, |
492 | 482 | ) |
493 | | - # FIXME: it seems that the index dtype should be derived from the dtype of shape/strides instead |
| 483 | + # FIXME: Derive the index dtype from the shape and stride dtypes. |
494 | 484 | size_ty = ScalarTy(index_dtype) |
495 | 485 | shape_vars = tuple(strictly_typed_const(extent, size_ty) for extent in shape) |
496 | 486 | stride_vars = tuple(strictly_typed_const(extent, size_ty) for extent in strides) |
497 | | - result.set_aggregate(ArrayValue(pointer, shape_vars, stride_vars)) |
498 | | - return result |
| 487 | + return make_aggregate(ArrayValue(pointer, shape_vars, stride_vars), array_ty) |
0 commit comments