aboutsummaryrefslogtreecommitdiffhomepage
path: root/ptx/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'ptx/src/test')
-rw-r--r--ptx/src/test/spirv_run/mod.rs35
-rw-r--r--ptx/src/test/spirv_run/mov.spvtxt69
-rw-r--r--ptx/src/test/spirv_run/mul_hi.spvtxt69
-rw-r--r--ptx/src/test/spirv_run/mul_lo.spvtxt64
4 files changed, 154 insertions, 83 deletions
diff --git a/ptx/src/test/spirv_run/mod.rs b/ptx/src/test/spirv_run/mod.rs
index 394e757..c1ef574 100644
--- a/ptx/src/test/spirv_run/mod.rs
+++ b/ptx/src/test/spirv_run/mod.rs
@@ -1,6 +1,9 @@
use crate::ptx;
use crate::translate;
-use rspirv::{binary::Disassemble, dr::{Block, Function, Instruction, Loader, Operand}};
+use rspirv::{
+ binary::Assemble,
+ dr::{Block, Function, Instruction, Loader, Operand},
+};
use spirv_headers::Word;
use spirv_tools_sys::{
spv_binary, spv_endianness_t, spv_parsed_instruction_t, spv_result_t, spv_target_env,
@@ -37,9 +40,9 @@ macro_rules! test_ptx {
}
test_ptx!(ld_st, [1u64], [1u64]);
-//test_ptx!(mov, [1u64], [1u64]);
-//test_ptx!(mul_lo, [1u64], [2u64]);
-//test_ptx!(mul_hi, [u64::max_value()], [1u64]);
+test_ptx!(mov, [1u64], [1u64]);
+test_ptx!(mul_lo, [1u64], [2u64]);
+test_ptx!(mul_hi, [u64::max_value()], [1u64]);
struct DisplayError<T: Display + Debug> {
err: T,
@@ -155,9 +158,31 @@ fn test_spvtxt_assert<'a>(
let mut loader = Loader::new();
rspirv::binary::parse_words(&parsed_spirv, &mut loader)?;
let spvtxt_mod = loader.module();
+ unsafe { spirv_tools::spvBinaryDestroy(spv_binary) };
if !is_spirv_fn_equal(&ptx_mod.functions[0], &spvtxt_mod.functions[0]) {
- panic!(ptx_mod.disassemble())
+ // We could simply use ptx_mod.disassemble, but SPIRV-Tools text formattinmg is so much nicer
+ let spv_from_ptx_binary = ptx_mod.assemble();
+ let mut spv_text: spirv_tools::spv_text = ptr::null_mut();
+ let result = unsafe {
+ spirv_tools::spvBinaryToText(
+ spv_context,
+ spv_from_ptx_binary.as_ptr(),
+ spv_from_ptx_binary.len(),
+ (spirv_tools::spv_binary_to_text_options_t::SPV_BINARY_TO_TEXT_OPTION_INDENT | spirv_tools::spv_binary_to_text_options_t::SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | spirv_tools::spv_binary_to_text_options_t::SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES).0,
+ &mut spv_text as *mut _,
+ ptr::null_mut()
+ )
+ };
+ assert_eq!(result, spv_result_t::SPV_SUCCESS);
+ let raw_text = unsafe {
+ std::slice::from_raw_parts((*spv_text).str_ as *const u8, (*spv_text).length)
+ };
+ let spv_from_ptx_text = unsafe { str::from_utf8_unchecked(raw_text) };
+ // TODO: stop leaking kernel text
+ unsafe { spirv_tools::spvContextDestroy(spv_context) };
+ panic!(spv_from_ptx_text);
}
+ unsafe { spirv_tools::spvContextDestroy(spv_context) };
Ok(())
}
diff --git a/ptx/src/test/spirv_run/mov.spvtxt b/ptx/src/test/spirv_run/mov.spvtxt
index 3f11b26..367a92a 100644
--- a/ptx/src/test/spirv_run/mov.spvtxt
+++ b/ptx/src/test/spirv_run/mov.spvtxt
@@ -1,26 +1,43 @@
-OpCapability GenericPointer
-OpCapability Linkage
-OpCapability Addresses
-OpCapability Kernel
-OpCapability Int64
-OpCapability Int8
-%1 = OpExtInstImport "OpenCL.std"
-OpMemoryModel Physical64 OpenCL
-OpEntryPoint Kernel %5 "mov"
-%2 = OpTypeVoid
-%3 = OpTypeInt 64 0
-%4 = OpTypeFunction %2 %3 %3
-%19 = OpTypePointer Generic %3
-%5 = OpFunction %2 None %4
-%6 = OpFunctionParameter %3
-%7 = OpFunctionParameter %3
-%18 = OpLabel
-%13 = OpCopyObject %3 %6
-%14 = OpCopyObject %3 %7
-%15 = OpConvertUToPtr %19 %13
-%16 = OpLoad %3 %15
-%100 = OpCopyObject %3 %16
-%17 = OpConvertUToPtr %19 %14
-OpStore %17 %100
-OpReturn
-OpFunctionEnd
+; SPIR-V
+; Version: 1.5
+; Generator: Khronos SPIR-V Tools Assembler; 0
+; Bound: 23
+; Schema: 0
+ OpCapability GenericPointer
+ OpCapability Linkage
+ OpCapability Addresses
+ OpCapability Kernel
+ OpCapability Int64
+ OpCapability Int8
+ %1 = OpExtInstImport "OpenCL.std"
+ OpMemoryModel Physical64 OpenCL
+ OpEntryPoint Kernel %2 "mov"
+ %void = OpTypeVoid
+ %ulong = OpTypeInt 64 0
+ %5 = OpTypeFunction %void %ulong %ulong
+%_ptr_Function_ulong = OpTypePointer Function %ulong
+%_ptr_Generic_ulong = OpTypePointer Generic %ulong
+ %2 = OpFunction %void None %5
+ %8 = OpFunctionParameter %ulong
+ %9 = OpFunctionParameter %ulong
+ %10 = OpLabel
+ %11 = OpVariable %_ptr_Function_ulong Function
+ %12 = OpVariable %_ptr_Function_ulong Function
+ %13 = OpVariable %_ptr_Function_ulong Function
+ %14 = OpVariable %_ptr_Function_ulong Function
+ OpStore %11 %8
+ OpStore %12 %9
+ %15 = OpLoad %ulong %11
+ %16 = OpConvertUToPtr %_ptr_Generic_ulong %15
+ %17 = OpLoad %ulong %16
+ OpStore %13 %17
+ %18 = OpLoad %ulong %13
+ %19 = OpCopyObject %ulong %18
+ OpStore %14 %19
+ %20 = OpLoad %ulong %12
+ %21 = OpLoad %ulong %14
+ %22 = OpConvertUToPtr %_ptr_Generic_ulong %20
+ OpStore %22 %21
+ OpReturn
+ OpFunctionEnd
+ \ No newline at end of file
diff --git a/ptx/src/test/spirv_run/mul_hi.spvtxt b/ptx/src/test/spirv_run/mul_hi.spvtxt
index db8943f..d25dd8a 100644
--- a/ptx/src/test/spirv_run/mul_hi.spvtxt
+++ b/ptx/src/test/spirv_run/mul_hi.spvtxt
@@ -1,26 +1,43 @@
-OpCapability GenericPointer
-OpCapability Linkage
-OpCapability Addresses
-OpCapability Kernel
-OpCapability Int64
-OpCapability Int8
-%1 = OpExtInstImport "OpenCL.std"
-OpMemoryModel Physical64 OpenCL
-OpEntryPoint Kernel %5 "mul_hi"
-%2 = OpTypeVoid
-%3 = OpTypeInt 64 0
-%4 = OpTypeFunction %2 %3 %3
-%19 = OpTypePointer Generic %3
-%5 = OpFunction %2 None %4
-%6 = OpFunctionParameter %3
-%7 = OpFunctionParameter %3
-%18 = OpLabel
-%13 = OpCopyObject %3 %6
-%14 = OpCopyObject %3 %7
-%15 = OpConvertUToPtr %19 %13
-%16 = OpLoad %3 %15
-%100 = OpCopyObject %3 %16
-%17 = OpConvertUToPtr %19 %14
-OpStore %17 %100
-OpReturn
-OpFunctionEnd
+; SPIR-V
+; Version: 1.5
+; Generator: Khronos SPIR-V Tools Assembler; 0
+; Bound: 24
+; Schema: 0
+ OpCapability GenericPointer
+ OpCapability Linkage
+ OpCapability Addresses
+ OpCapability Kernel
+ OpCapability Int64
+ OpCapability Int8
+ %1 = OpExtInstImport "OpenCL.std"
+ OpMemoryModel Physical64 OpenCL
+ OpEntryPoint Kernel %2 "mul_hi"
+ %void = OpTypeVoid
+ %ulong = OpTypeInt 64 0
+ %5 = OpTypeFunction %void %ulong %ulong
+%_ptr_Function_ulong = OpTypePointer Function %ulong
+%_ptr_Generic_ulong = OpTypePointer Generic %ulong
+ %ulong_2 = OpConstant %ulong 2
+ %2 = OpFunction %void None %5
+ %9 = OpFunctionParameter %ulong
+ %10 = OpFunctionParameter %ulong
+ %11 = OpLabel
+ %12 = OpVariable %_ptr_Function_ulong Function
+ %13 = OpVariable %_ptr_Function_ulong Function
+ %14 = OpVariable %_ptr_Function_ulong Function
+ %15 = OpVariable %_ptr_Function_ulong Function
+ OpStore %12 %9
+ OpStore %13 %10
+ %16 = OpLoad %ulong %12
+ %17 = OpConvertUToPtr %_ptr_Generic_ulong %16
+ %18 = OpLoad %ulong %17
+ OpStore %14 %18
+ %19 = OpLoad %ulong %14
+ %20 = OpExtInst %ulong %1 u_mul_hi %19 %ulong_2
+ OpStore %15 %20
+ %21 = OpLoad %ulong %13
+ %22 = OpLoad %ulong %15
+ %23 = OpConvertUToPtr %_ptr_Generic_ulong %21
+ OpStore %23 %22
+ OpReturn
+ OpFunctionEnd
diff --git a/ptx/src/test/spirv_run/mul_lo.spvtxt b/ptx/src/test/spirv_run/mul_lo.spvtxt
index 66e7bc1..4d7c2d8 100644
--- a/ptx/src/test/spirv_run/mul_lo.spvtxt
+++ b/ptx/src/test/spirv_run/mul_lo.spvtxt
@@ -1,26 +1,38 @@
-OpCapability GenericPointer
-OpCapability Linkage
-OpCapability Addresses
-OpCapability Kernel
-OpCapability Int64
-OpCapability Int8
-%1 = OpExtInstImport "OpenCL.std"
-OpMemoryModel Physical64 OpenCL
-OpEntryPoint Kernel %5 "mul_lo"
-%2 = OpTypeVoid
-%3 = OpTypeInt 64 0
-%4 = OpTypeFunction %2 %3 %3
-%19 = OpTypePointer Generic %3
-%5 = OpFunction %2 None %4
-%6 = OpFunctionParameter %3
-%7 = OpFunctionParameter %3
-%18 = OpLabel
-%13 = OpCopyObject %3 %6
-%14 = OpCopyObject %3 %7
-%15 = OpConvertUToPtr %19 %13
-%16 = OpLoad %3 %15
-%100 = OpCopyObject %3 %16
-%17 = OpConvertUToPtr %19 %14
-OpStore %17 %100
-OpReturn
-OpFunctionEnd
+ OpCapability GenericPointer
+ OpCapability Linkage
+ OpCapability Addresses
+ OpCapability Kernel
+ OpCapability Int64
+ OpCapability Int8
+ %1 = OpExtInstImport "OpenCL.std"
+ OpMemoryModel Physical64 OpenCL
+ OpEntryPoint Kernel %5 "mul_lo"
+ %void = OpTypeVoid
+ %ulong = OpTypeInt 64 0
+ %4 = OpTypeFunction %void %ulong %ulong
+%_ptr_Function_ulong = OpTypePointer Function %ulong
+%_ptr_Generic_ulong = OpTypePointer Generic %ulong
+ %ulong_2 = OpConstant %ulong 2
+ %5 = OpFunction %void None %4
+ %6 = OpFunctionParameter %ulong
+ %7 = OpFunctionParameter %ulong
+ %21 = OpLabel
+ %8 = OpVariable %_ptr_Function_ulong Function
+ %9 = OpVariable %_ptr_Function_ulong Function
+ %10 = OpVariable %_ptr_Function_ulong Function
+ %11 = OpVariable %_ptr_Function_ulong Function
+ OpStore %8 %6
+ OpStore %9 %7
+ %12 = OpLoad %ulong %8
+ %19 = OpConvertUToPtr %_ptr_Generic_ulong %12
+ %13 = OpLoad %ulong %19
+ OpStore %10 %13
+ %14 = OpLoad %ulong %10
+ %15 = OpIMul %ulong %14 %ulong_2
+ OpStore %11 %15
+ %16 = OpLoad %ulong %9
+ %17 = OpLoad %ulong %11
+ %20 = OpConvertUToPtr %_ptr_Generic_ulong %16
+ OpStore %20 %17
+ OpReturn
+ OpFunctionEnd