Skip to content

Commit

Permalink
Example of cross compilation to arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasvasilache committed Jul 7, 2021
1 parent 2e87951 commit ec368c0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
18 changes: 9 additions & 9 deletions multi_reduction.mlir
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Tested on Intel(R) Xeon(R) CPU @ 2.00GHz w/ AVX512
func @compute(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
call @compute_v1(%input, %filter, %output) : (memref<${M}xf32>, memref<${K}xf32>, memref<${N}xf32>) -> ()
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
call @compute_v5(%input, %filter, %output) : (memref<${M}xf32>, memref<${K}xf32>, memref<${N}xf32>) -> ()
return
}

Expand All @@ -17,7 +17,7 @@ func @compute(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : m
// IPC: 2.28
// Block RThroughput: 5.0
func @compute_v1(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
%c0 = constant 0 : index
%c1 = constant 1 : index
%c2 = constant 2 : index
Expand Down Expand Up @@ -61,7 +61,7 @@ func @compute_v1(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output
// IPC: 2.64
// Block RThroughput: 5.0
func @compute_v2(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
%c0 = constant 0 : index
%c1 = constant 1 : index
%c2 = constant 2 : index
Expand Down Expand Up @@ -106,7 +106,7 @@ func @compute_v2(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output
// IPC: 3.32
// Block RThroughput: 5.5
func @compute_v3(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
%c0 = constant 0 : index
%c1 = constant 1 : index
%c2 = constant 2 : index
Expand Down Expand Up @@ -155,7 +155,7 @@ func @compute_v3(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output
// IPC: 2.70
// Block RThroughput: 5.5
func @compute_v4(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
%c0 = constant 0 : index
%c1 = constant 1 : index
%c2 = constant 2 : index
Expand Down Expand Up @@ -210,7 +210,7 @@ func @compute_v4(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output
// IPC: 3.32
// Block RThroughput: 5.5
func @compute_v5(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
%c0 = constant 0 : index
%c1 = constant 1 : index
%c2 = constant 2 : index
Expand Down Expand Up @@ -258,7 +258,7 @@ func @compute_v5(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output
// IPC: 1.90
// Block RThroughput: 64.0
func @compute_v6(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
%c0 = constant 0 : index
%c1 = constant 1 : index
%c2 = constant 2 : index
Expand Down Expand Up @@ -292,7 +292,7 @@ func @compute_v6(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output
// Size 18 * 3 -> 16
// ~1.9 GFlops/s
func @compute_v7(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
%c0 = constant 0 : index
%c1 = constant 1 : index
%c2 = constant 2 : index
Expand Down
8 changes: 4 additions & 4 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
'-O3',
'-march=arm64',
]
opt_flags = opt_flags_skylake_avx512
opt_flags = opt_flags_armv8

llc_flags_common = [
'-O3',
Expand All @@ -48,7 +48,7 @@
llc_flags_armv8 = [
'-march=arm64',
]
llc_flags = llc_flags_common + llc_flags_skylake_avx512
llc_flags = llc_flags_common + llc_flags_armv8


# Note: llvm-mca requires a processor to run properly,
Expand All @@ -67,7 +67,7 @@
'-march=arm64',
'-mcpu=cortex-a34',
]
llvm_mca_flags = llvm_mca_common + llvm_mca_flags_skylake_avx512
llvm_mca_flags = llvm_mca_common + llvm_mca_flags_armv8

objdump_flags = [
'-d',
Expand Down Expand Up @@ -170,7 +170,7 @@ def run(args):
mlir_file, mlir_outfile = compile_to_llvm_dialect(args)
obj_file = compile_to_object(args, mlir_outfile)
objdump_and_llvm_mca(args, obj_file)
run_and_check(args, mlir_file, mlir_outfile)
# run_and_check(args, mlir_file, mlir_outfile)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion scalar.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// IPC: 3.30
// Block RThroughput: 49.5
func @compute(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
%c0 = constant 0 : index
%c1 = constant 1 : index
%c3 = constant ${K} : index
Expand Down
4 changes: 2 additions & 2 deletions shuffled_contraction_parallel_reduction.mlir
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Tested on Intel(R) Xeon(R) CPU @ 2.00GHz w/ AVX512
func @compute(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
call @compute_v1(%input, %filter, %output) : (memref<${M}xf32>, memref<${K}xf32>, memref<${N}xf32>) -> ()
return
}
Expand Down Expand Up @@ -28,7 +28,7 @@ func @compute(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : m
// IPC: 1.54
// Block RThroughput: 46.0
func @compute_v1(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
%c0 = constant 0 : index
%c1 = constant 1 : index
%c2 = constant 2 : index
Expand Down
10 changes: 5 additions & 5 deletions shuffled_contraction_reduction_parallel.mlir
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Tested on Intel(R) Xeon(R) CPU @ 2.00GHz w/ AVX512
func @compute(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
call @compute_v4(%input, %filter, %output) : (memref<${M}xf32>, memref<${K}xf32>, memref<${N}xf32>) -> ()
return
}
Expand Down Expand Up @@ -28,7 +28,7 @@ func @compute(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : m
// IPC: 2.84
// Block RThroughput: 5.5
func @compute_v1(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
%c0 = constant 0 : index
%c1 = constant 1 : index
%c2 = constant 2 : index
Expand Down Expand Up @@ -60,7 +60,7 @@ func @compute_v1(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output
// IPC: 2.60
// Block RThroughput: 5.5
func @compute_v2(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
%c0 = constant 0 : index
%c1 = constant 1 : index
%c2 = constant 2 : index
Expand Down Expand Up @@ -101,7 +101,7 @@ func @compute_v2(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output
// IPC: 2.61
// Block RThroughput: 5.0
func @compute_v3(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
%c0 = constant 0 : index
%c1 = constant 1 : index
%c2 = constant 2 : index
Expand Down Expand Up @@ -143,7 +143,7 @@ func @compute_v3(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output
// IPC: 2.28
// Block RThroughput: 5.0
func @compute_v4(%input : memref<${M}xf32>, %filter : memref<${K}xf32>, %output : memref<${N}xf32>)
attributes { passthrough = ["inline", ["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]} {
attributes { passthrough = ["inline", ["prefer-vector-width", "128"]]} {
%c0 = constant 0 : index
%c1 = constant 1 : index
%c2 = constant 2 : index
Expand Down

0 comments on commit ec368c0

Please sign in to comment.