Skip to content

Commit

Permalink
[Kernels] Removed aligned_alloc and replace aligned_alloc with new al…
Browse files Browse the repository at this point in the history
…loc (#32168)

Removed `aligned_alloc` methods from `DTypePointer` and `Pointer`
structs and replaced them by `aligned_alloc` with new method signature.

[Internal Link]

---------

Co-authored-by: Wei Han <[email protected]>

modular-orig-commit: a1ed96e853e38b376c6866e3eb133e15a2cea8be
  • Loading branch information
palebluedot19 authored Feb 16, 2024
1 parent 235ad4b commit 4529249
Showing 1 changed file with 4 additions and 34 deletions.
38 changes: 4 additions & 34 deletions stdlib/src/memory/unsafe.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -708,30 +708,14 @@ struct Pointer[

@staticmethod
@always_inline
fn alloc(count: Int) -> Self:
"""Heap-allocates a number of element of the specified type.
Args:
count: The number of elements to allocate (note that this is not
the bytecount).
Returns:
A new Pointer object which has been allocated on the heap.
"""
return Self.aligned_alloc(alignof[type](), count)

@staticmethod
@always_inline
fn aligned_alloc(
alignment: Int, count: Int
) -> Pointer[type, address_space]:
fn alloc(count: Int, /, *, alignment: Int = alignof[type]()) -> Self:
"""Heap-allocates a number of element of the specified type using
the specified alignment.
Args:
alignment: The alignment used for the allocation.
count: The number of elements to allocate (note that this is not
the bytecount).
alignment: The alignment used for the allocation.
Returns:
A new Pointer object which has been allocated on the heap.
Expand Down Expand Up @@ -1105,28 +1089,14 @@ struct DTypePointer[

@staticmethod
@always_inline
fn alloc(count: Int) -> Self:
"""Heap-allocates a number of element of the specified type.
Args:
count: The number of elements to allocate (note that this is not
the bytecount).
Returns:
A new `DTypePointer` object which has been allocated on the heap.
"""
return Self.pointer_type.aligned_alloc(alignof[type](), count)

@staticmethod
@always_inline
fn aligned_alloc(alignment: Int, count: Int) -> Self:
fn alloc(count: Int, /, *, alignment: Int = alignof[type]()) -> Self:
"""Heap-allocates a number of element of the specified type using
the specified alignment.
Args:
alignment: The alignment used for the allocation.
count: The number of elements to allocate (note that this is not
the bytecount).
alignment: The alignment used for the allocation.
Returns:
A new `DTypePointer` object which has been allocated on the heap.
Expand Down

0 comments on commit 4529249

Please sign in to comment.