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

LLVM unit tests #324

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

Conversation

JoelleJS
Copy link
Contributor

@JoelleJS JoelleJS commented Jan 15, 2025

@JoelleJS JoelleJS changed the title LLVM unit tests (issue #312) LLVM unit tests Jan 15, 2025
@vosen
Copy link
Owner

vosen commented Jan 20, 2025

I don't see the Rust code to generate those tests. Not sure if I botched the explanation, your code is still in progress or you forgot to check it in or, but the tests are one part. The other part is Rust code: for each file there should be a rust unit test (generated by extending the existing macro that generates unit tests) to verify that .ll match LLVM bitcode generated by the compiler

@JoelleJS
Copy link
Contributor Author

@vosen Yep, still working on that part. Just wanted the .ll files committed

@JoelleJS JoelleJS force-pushed the issue-312-llvm-unit-tests branch from 13d308c to 8692956 Compare February 5, 2025 15:26
@JoelleJS JoelleJS force-pushed the issue-312-llvm-unit-tests branch from 8692956 to b6a03d2 Compare February 5, 2025 15:27
@JoelleJS
Copy link
Contributor Author

JoelleJS commented Feb 5, 2025

Okay, the tests seem to be working individually, e.g. cargo test -p ptx -- ::add_llvm. However, when running cargo test -p ptx -- llvm --nocapture I can see that it only runs a few tests and then fails with SIGSEGV or SIGABRT.

I'm thinking there is some kind of memory leak, but I haven't been able to find it. Perhaps your trained eyes see it quicker @vosen

@vosen
Copy link
Owner

vosen commented Feb 5, 2025 via email

@JoelleJS
Copy link
Contributor Author

JoelleJS commented Feb 6, 2025

@vosen That was exactly it, good catch.

All tests succeed, as expected (the .ll files were generated from the LLVM IR produced in the tests). The assumption is that the files are currently correct.

Currently, when the assertion fails it looks like this:

assertion `left == right` failed
  left: "declare i32 @__zluda_ptx_impl_sreg_tid(i8) #0\n\ndeclare i32 @__zluda_ptx_impl_sreg_ntid(i8) #0\n\ndeclare i32 @__zluda_ptx_impl_sreg_ctaid(i8) #0\n\ndeclare i32 @__zluda_ptx_impl_sreg_nctaid(i8) #0\n\ndeclare i32 @__zluda_ptx_impl_sreg_clock() #0\n\ndeclare i32 @__zluda_ptx_impl_sreg_lanemask_lt() #0\n\ndefine amdgpu_kernel void @neg(ptr addrspace(4) byref(i64) %\"34\", ptr addrspace(4) byref(i64) %\"35\") #0 {\n  %\"36\" = alloca i64, align 8, addrspace(5)\n  %\"37\" = alloca i64, align 8, addrspace(5)\n  %\"38\" = alloca i32, align 4, addrspace(5)\n  br label %1\n\n1:                                                ; preds = %0\n  %\"39\" = load i64, ptr addrspace(4) %\"34\", align 4\n  store i64 %\"39\", ptr addrspace(5) %\"36\", align 4\n  %\"40\" = load i64, ptr addrspace(4) %\"35\", align 4\n  store i64 %\"40\", ptr addrspace(5) %\"37\", align 4\n  %\"42\" = load i64, ptr addrspace(5) %\"36\", align 4\n  %\"47\" = inttoptr i64 %\"42\" to ptr\n  %\"41\" = load i32, ptr %\"47\", align 4\n  store i32 %\"41\", ptr addrspace(5) %\"38\", align 4\n  %\"44\" = load i32, ptr addrspace(5) %\"38\", align 4\n  %\"43\" = sub i32 0, %\"44\"\n  store i32 %\"43\", ptr addrspace(5) %\"38\", align 4\n  %\"45\" = load i64, ptr addrspace(5) %\"37\", align 4\n  %\"46\" = load i32, ptr addrspace(5) %\"38\", align 4\n  %\"48\" = inttoptr i64 %\"45\" to ptr\n  store i32 %\"46\", ptr %\"48\", align 4\n  ret void\n}\n\nattributes #0 = { \"amdgpu-unsafe-fp-atomics\"=\"true\" \"no-trapping-math\"=\"true\" \"uniform-work-group-size\"=\"true\" }"
 right: "declare i32 @__zluda_ptx_impl_sreg_tid(i8) #0\n\ndeclare i32 @__zluda_ptx_impl_sreg_ntid(i8) #0\n\ndeclare i32 @__zluda_ptx_impl_sreg_ctaid(i8) #0\n\ndeclare i32 @__zluda_ptx_impl_sreg_nctaid(i8) #\n\ndeclare i32 @__zluda_ptx_impl_sreg_clock() #0\n\ndeclare i32 @__zluda_ptx_impl_sreg_lanemask_lt() #0\n\ndefine amdgpu_kernel void @neg(ptr addrspace(4) byref(i64) %\"34\", ptr addrspace(4) byref(i64) %\"35\") #0 {\n  %\"36\" = alloca i64, align 8, addrspace(5)\n  %\"37\" = alloca i64, align 8, addrspace(5)\n  %\"38\" = alloca i32, align 4, addrspace(5)\n  br label %1\n\n1:                                                ; preds = %0\n  %\"39\" = load i64, ptr addrspace(4) %\"34\", align 4\n  store i64 %\"39\", ptr addrspace(5) %\"36\", align 4\n  %\"40\" = load i64, ptr addrspace(4) %\"35\", align 4\n  store i64 %\"40\", ptr addrspace(5) %\"37\", align 4\n  %\"42\" = load i64, ptr addrspace(5) %\"36\", align 4\n  %\"47\" = inttoptr i64 %\"42\" to ptr\n  %\"41\" = load i32, ptr %\"47\", align 4\n  store i32 %\"41\", ptr addrspace(5) %\"38\", align 4\n  %\"44\" = load i32, ptr addrspace(5) %\"38\", align 4\n  %\"43\" = sub i32 0, %\"44\"\n  store i32 %\"43\", ptr addrspace(5) %\"38\", align 4\n  %\"45\" = load i64, ptr addrspace(5) %\"37\", align 4\n  %\"46\" = load i32, ptr addrspace(5) %\"38\", align 4\n  %\"48\" = inttoptr i64 %\"45\" to ptr\n  store i32 %\"46\", ptr %\"48\", align 4\n  ret void\n}\n\nattributes #0 = { \"amdgpu-unsafe-fp-atomics\"=\"true\" \"no-trapping-math\"=\"true\" \"uniform-work-group-size\"=\"true\" }"

These can be copied and diffed of course, but I think it would be more convenient to use the pretty_assertions crate (link) to show a clear diff in the output itself. Do you agree?

@JoelleJS JoelleJS marked this pull request as ready for review February 6, 2025 10:54
@JoelleJS
Copy link
Contributor Author

JoelleJS commented Feb 6, 2025

Marked this as ready but I just realized I forgot the following point:

If there's the a variable set (pick a name you like) that points to a directory then it also is written to the directory.

Will do that soon.

@JoelleJS JoelleJS marked this pull request as draft February 6, 2025 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants