-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add makefile passes * move memory management to linalg * clear memory space pass * snax renaming * snax renaming * add new passes to makefile * fix regex * add snax runtime library * update renaming in tests * fix simple copy kernel * fix alloc kernel * use regular ints * better comment
- Loading branch information
1 parent
8ff15dd
commit 82a4394
Showing
14 changed files
with
113 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from xdsl.dialects import builtin, memref, func | ||
from xdsl.ir import MLContext | ||
from xdsl.passes import ModulePass | ||
|
||
|
||
class ClearMemorySpace(ModulePass): | ||
name = "clear-memory-space" | ||
|
||
def apply(self, ctx: MLContext, module: builtin.ModuleOp) -> None: | ||
# helper function to clear the memory space of a memref | ||
def clear_memory_space(t): | ||
if isinstance(t, memref.MemRefType): | ||
if not isinstance(t.memory_space, builtin.NoneAttr): | ||
return memref.MemRefType.from_element_type_and_shape( | ||
t.element_type, | ||
t.get_shape(), | ||
t.layout, | ||
builtin.NoneAttr(), | ||
) | ||
return t | ||
|
||
for op_in_module in module.walk(): | ||
for operand in op_in_module.operands: | ||
operand.type = clear_memory_space(operand.type) | ||
|
||
if isinstance(op_in_module, func.FuncOp): | ||
# special case for func ops because func ops do not have | ||
# operands, they have function_types which have ins & outs | ||
# Define new function type with updated inputs and outputs | ||
# mapped to a default memory space | ||
new_function_type = builtin.FunctionType.from_lists( | ||
map(clear_memory_space, op_in_module.function_type.inputs), | ||
map(clear_memory_space, op_in_module.function_type.outputs), | ||
) | ||
|
||
op_in_module.function_type = new_function_type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
func.func public @simple_alloc() -> (memref<10xi32>) { | ||
%alloc = "memref.alloc"() {"alignment" = 64 : i64, operand_segment_sizes = array<i32: 0, 0>} : () -> memref<10xi32> | ||
return %alloc : memref<10xi32> | ||
func.func public @simple_alloc() -> (memref<10xi32, 1 : i32>) { | ||
%alloc = "memref.alloc"() {"alignment" = 64 : i64, operand_segment_sizes = array<i32: 0, 0>} : () -> memref<10xi32, 1 : i32> | ||
return %alloc : memref<10xi32, 1 : i32> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include <snrt.h> | ||
#include <stdint.h> | ||
|
||
int8_t *allocated_pointer; | ||
|
||
int8_t *_mlir_memref_to_llvm_alloc(uint32_t size) { | ||
/* This calls malloc on the DMA core | ||
* --> requires mlir opt to compile with: | ||
* --convert-memref-to-llvm="use-generic-functions index-bitwidth=32" | ||
* To ensure that all cores in the cluster come up with the correct | ||
*/ | ||
if (snrt_is_dm_core()) { | ||
allocated_pointer = (int8_t *)snrt_l1alloc(size); | ||
} | ||
snrt_cluster_hw_barrier(); | ||
return allocated_pointer; | ||
}; | ||
|
||
void _mlir_ciface_snax_cluster_hw_barrier() { | ||
snrt_cluster_hw_barrier(); | ||
return; | ||
} | ||
|
||
void _mlir_ciface_snax_dma_1d_transfer(size_t *source, size_t *destination, | ||
size_t size) { | ||
snrt_dma_start_1d((void *)destination, (void *)source, size * sizeof(size_t)); | ||
return; | ||
} | ||
|
||
int _mlir_ciface_snax_is_dm_core() { return snrt_is_dm_core(); } | ||
|
||
int _mlir_ciface_snax_is_compute_core() { return snrt_is_compute_core(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters