mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-08-02 22:30:41 +00:00
LLVM unit tests: first attempt
This commit is contained in:
parent
c27102d1e6
commit
b6a03d20a3
2 changed files with 44 additions and 0 deletions
|
@ -24,6 +24,7 @@
|
||||||
// shows it fails inside amdgpu-isel. You can get a little bit furthr with "-mllvm -global-isel",
|
// shows it fails inside amdgpu-isel. You can get a little bit furthr with "-mllvm -global-isel",
|
||||||
// but it will too fail similarly, but with "unable to legalize instruction"
|
// but it will too fail similarly, but with "unable to legalize instruction"
|
||||||
|
|
||||||
|
use std::alloc::{alloc, dealloc, handle_alloc_error, Layout};
|
||||||
use std::array::TryFromSliceError;
|
use std::array::TryFromSliceError;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::ffi::{CStr, NulError};
|
use std::ffi::{CStr, NulError};
|
||||||
|
@ -32,6 +33,7 @@ use std::{i8, ptr};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use llvm_zluda::analysis::{LLVMVerifierFailureAction, LLVMVerifyModule};
|
use llvm_zluda::analysis::{LLVMVerifierFailureAction, LLVMVerifyModule};
|
||||||
|
use llvm_zluda::bit_reader::LLVMParseBitcode2;
|
||||||
use llvm_zluda::bit_writer::LLVMWriteBitcodeToMemoryBuffer;
|
use llvm_zluda::bit_writer::LLVMWriteBitcodeToMemoryBuffer;
|
||||||
use llvm_zluda::{core::*, *};
|
use llvm_zluda::{core::*, *};
|
||||||
use llvm_zluda::{prelude::*, LLVMZludaBuildAtomicRMW};
|
use llvm_zluda::{prelude::*, LLVMZludaBuildAtomicRMW};
|
||||||
|
@ -148,6 +150,24 @@ impl std::fmt::Debug for Message {
|
||||||
|
|
||||||
pub struct MemoryBuffer(LLVMMemoryBufferRef);
|
pub struct MemoryBuffer(LLVMMemoryBufferRef);
|
||||||
|
|
||||||
|
impl MemoryBuffer {
|
||||||
|
pub fn print_as_asm(&self) -> &str {
|
||||||
|
unsafe {
|
||||||
|
let layout = Layout::new::<LLVMModuleRef>();
|
||||||
|
let p_module = alloc(layout);
|
||||||
|
if p_module.is_null() {
|
||||||
|
handle_alloc_error(layout);
|
||||||
|
}
|
||||||
|
LLVMParseBitcode2(self.0, p_module as *mut LLVMModuleRef);
|
||||||
|
let asm = LLVMPrintModuleToString(*(p_module as *mut LLVMModuleRef));
|
||||||
|
LLVMDisposeModule(*(p_module as *mut LLVMModuleRef));
|
||||||
|
dealloc(p_module, layout);
|
||||||
|
let asm = CStr::from_ptr(asm);
|
||||||
|
asm.to_str().unwrap().trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Drop for MemoryBuffer {
|
impl Drop for MemoryBuffer {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -28,6 +28,17 @@ macro_rules! test_ptx {
|
||||||
test_cuda_assert(stringify!($fn_name), ptx, &input, &mut output)
|
test_cuda_assert(stringify!($fn_name), ptx, &input, &mut output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
paste::item! {
|
||||||
|
#[test]
|
||||||
|
fn [<$fn_name _llvm>]() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let fn_name = stringify!($fn_name);
|
||||||
|
println!("{}", fn_name);
|
||||||
|
let ptx = include_str!(concat!(stringify!($fn_name), ".ptx"));
|
||||||
|
let ll = include_str!(concat!("../ll/", stringify!($fn_name), ".ll")).trim();
|
||||||
|
test_llvm_assert(ptx, &ll)
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
($fn_name:ident) => {};
|
($fn_name:ident) => {};
|
||||||
|
@ -223,6 +234,19 @@ fn test_hip_assert<
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_llvm_assert<
|
||||||
|
'a,
|
||||||
|
>(
|
||||||
|
ptx_text: &'a str,
|
||||||
|
expected_ll: &str
|
||||||
|
) -> Result<(), Box<dyn error::Error + 'a>> {
|
||||||
|
let ast = ptx_parser::parse_module_checked(ptx_text).unwrap();
|
||||||
|
let llvm_ir = pass::to_llvm_module(ast).unwrap();
|
||||||
|
let actual_ll = llvm_ir.llvm_ir.print_as_asm();
|
||||||
|
assert_eq!(actual_ll, expected_ll);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn test_cuda_assert<
|
fn test_cuda_assert<
|
||||||
'a,
|
'a,
|
||||||
Input: From<u8> + Debug + Copy + PartialEq,
|
Input: From<u8> + Debug + Copy + PartialEq,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue