exaloop / codon

A high-performance, zero-overhead, extensible Python compiler using LLVM
https://docs.exaloop.io/codon
Other
13.95k stars 498 forks source link

simd program #511

Closed iSunfield closed 5 months ago

iSunfield commented 6 months ago

I'm looking to run SIMD code on CODON, and I've successfully used the simd.codon file from the stdlib/experimental directory by importing it. Now, I want to extend the functionalities of simd.codon and have tried copying it to my local directory, but I'm encountering compilation errors as below.

from experimental.simd import * 

A:u8x16

A=u8x16(u8(10))
print(A)

<10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10>

When I tried importing the simd.codon file from my local directory, I encountered the following result:

from simd import * 

A:u8x16

A=u8x16(u8(10))
print(A)

error: LLVM: error: value doesn't match function result type '{}'
        ret <16 x i8> %1
            ^
 (simd.Vec._mm_set1_epi8:0[UInt[8]])

Is there any special processing in the standard library code to treat LLVM's <16 x i8> type as equivalent to CODON's Vec[u8, 16] type?

iSunfield commented 6 months ago

Although I was testing whether AVX-512 instructions could be directly executed from codon, I have managed to execute the _mm512_set1_epi8 instruction following the steps below, so I am reporting this as a self-response.

A:Vec[i8,64]

A=Vec[i8,64]._mm512_set1_epi8(Int8)

PtrA = ptr(A).as_byte() for i in range(16): print(int(PtrA[i]))


- Execution by codon command, need --mattr=+avx512bw option for AVX-512

codon run --mattr=+avx512bw -release TestCode.codon

10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10

inumanag commented 5 months ago

Thank you for the fix! Our SIMD support is still indeed in the early-stage development.