Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The result of assert is changed with/without a print statement. #519

Open
iSunfield opened this issue Dec 27, 2023 · 1 comment
Open

The result of assert is changed with/without a print statement. #519

iSunfield opened this issue Dec 27, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@iSunfield
Copy link

iSunfield commented Dec 27, 2023

I'm implementing AVX-512 code in Codon and testing the _mm512_permutex2var_epi8 function. I'm experiencing strange behavior with the Codon compiler. The result of the assert changes when a print statement is present or absent. Below is the sample code. When I insert 'print(int(PtrX[0]))', the result becomes True, but if I comment it out, it turns False. Similarly, printing 'NgNo' results in True, but not printing it leads to False. I'm concerned that the 'Correct' variable might be getting corrupted. Additionally, executing this code requires the --mattr=+avx512bw option. In debugging with Codon, it's necessary to display results using print statements, and the presence or absence of these print statements changes the outcomes. Could you advise any solution to this issue ?

#-- Add below code to experimental/sdmi.codon
    @llvm
    @inline
    def _mm512_loadu_m_si512(data:Ptr[i8]) -> Vec[i8, 64]:
        %m512_val = call <64 x i8> asm sideeffect "vmovdqu32 $1, $0", "=v,p"(i8* %data)
        ret <64 x i8> %m512_val

    @llvm
    @inline
    def _mm512_permutex2var_epi8(a:Vec[i8, 64], idx:Vec[i8, 64], b:Vec[i8, 64]) -> Vec[i8, 64]:
        %m512_val = call <64 x i8> asm sideeffect "vpermi2b $2, $1, $0","=v,v,v,v"(<64 x i8> %a, <64 x i8> %b, <64 x i8> %idx)    
        ret <64 x i8> %m512_val
#-------------------------------------------------------

#-- Codon test code ----
from experimental.simd import * 
from random import *

A:Vec[i8,64]
i:int
Correct:bool=True

#-- AVX-512 Array --
XDt = Array[i8](64)
YDt = Array[i8](64)
#-- Set XDt --
for i in range(64):
    XDt[i] = i8(i)
X=Vec[i8,64]._mm512_loadu_m_si512(XDt.ptr)

for i in range(64):
    YDt[i] = i8(-i)
Y=Vec[i8,64]._mm512_loadu_m_si512(YDt.ptr)

IndexDt = Array[i8](64)
for i in range(64):
    if i % 2 == 0:
        IndexDt[i]=i8(i)
    else:
        IndexDt[i]=i8(i+64)

Index = Vec[i8,64]._mm512_loadu_m_si512(IndexDt.ptr)
A = Vec[i8,64]._mm512_permutex2var_epi8(X,Index,Y)
PtrA = __ptr__(A).as_byte()

PtrX = __ptr__(X).as_byte()
PtrY = __ptr__(Y).as_byte()
PtrIndex = __ptr__(Index).as_byte()

#----------------------------------------------
#---  Add print statement, result is True  ---
#----------------------------------------------
print(int(PtrX[0]))                
                                       
Correct = True
NgNo : int = -255
for i in range(64):
    if int(PtrIndex[i]) < 64:
        if int(PtrA[i])!=int(PtrX[i]):
            NgNo = i
            Correct = False
    else:
        if int(PtrA[i])!=int(PtrY[i]):
            NgNo = -i
            Correct = False

#-- Without print NgNo ==>  the result is False 
print("_mm512_permutex2var_epi8 test:",Correct)
#-- With print NgNo variable ==> result is True
#print("_mm512_permutex2var_epi8 test:",Correct,NgNo)

assert Correct,"_mm512_permutex2var_epi8 Test:Error"

#-- To execute this code, the --mattr option is required.
codon run  --mattr=+avx512bw -release FileName
@inumanag inumanag self-assigned this Jan 29, 2024
@inumanag inumanag added the bug Something isn't working label Jan 29, 2024
@inumanag
Copy link
Contributor

That is certainly a bug—thank you for the report. Will take a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants