mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-07-25 13:16:23 +03:00
Fix buggy handling of u8 shared memory
This commit is contained in:
@ -137,6 +137,7 @@ test_ptx!(stateful_ld_st_simple, [121u64], [121u64]);
|
|||||||
test_ptx!(stateful_ld_st_ntid, [123u64], [123u64]);
|
test_ptx!(stateful_ld_st_ntid, [123u64], [123u64]);
|
||||||
test_ptx!(stateful_ld_st_ntid_chain, [12651u64], [12651u64]);
|
test_ptx!(stateful_ld_st_ntid_chain, [12651u64], [12651u64]);
|
||||||
test_ptx!(stateful_ld_st_ntid_sub, [96311u64], [96311u64]);
|
test_ptx!(stateful_ld_st_ntid_sub, [96311u64], [96311u64]);
|
||||||
|
test_ptx!(shared_ptr_take_address, [97815231u64], [97815231u64]);
|
||||||
|
|
||||||
struct DisplayError<T: Debug> {
|
struct DisplayError<T: Debug> {
|
||||||
err: T,
|
err: T,
|
||||||
@ -261,6 +262,7 @@ fn test_spvtxt_assert<'a>(
|
|||||||
let ast = ptx::ModuleParser::new().parse(&mut errors, ptx_txt)?;
|
let ast = ptx::ModuleParser::new().parse(&mut errors, ptx_txt)?;
|
||||||
assert!(errors.len() == 0);
|
assert!(errors.len() == 0);
|
||||||
let spirv_module = translate::to_spirv_module(ast)?;
|
let spirv_module = translate::to_spirv_module(ast)?;
|
||||||
|
eprintln!("{}", rspirv::binary::Disassemble::disassemble(&spirv_module.spirv));
|
||||||
let spv_context =
|
let spv_context =
|
||||||
unsafe { spirv_tools::spvContextCreate(spv_target_env::SPV_ENV_UNIVERSAL_1_3) };
|
unsafe { spirv_tools::spvContextCreate(spv_target_env::SPV_ENV_UNIVERSAL_1_3) };
|
||||||
assert!(spv_context != ptr::null_mut());
|
assert!(spv_context != ptr::null_mut());
|
||||||
|
27
ptx/src/test/spirv_run/shared_ptr_take_address.ptx
Normal file
27
ptx/src/test/spirv_run/shared_ptr_take_address.ptx
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
.version 6.5
|
||||||
|
.target sm_30
|
||||||
|
.address_size 64
|
||||||
|
|
||||||
|
.extern .shared .align 4 .b8 shared_mem[];
|
||||||
|
|
||||||
|
.visible .entry shared_ptr_take_address(
|
||||||
|
.param .u64 input,
|
||||||
|
.param .u64 output
|
||||||
|
)
|
||||||
|
{
|
||||||
|
.reg .u64 in_addr;
|
||||||
|
.reg .u64 out_addr;
|
||||||
|
.reg .u64 shared_addr;
|
||||||
|
.reg .u64 temp1;
|
||||||
|
.reg .u64 temp2;
|
||||||
|
|
||||||
|
ld.param.u64 in_addr, [input];
|
||||||
|
ld.param.u64 out_addr, [output];
|
||||||
|
mov.u64 shared_addr, shared_mem;
|
||||||
|
|
||||||
|
ld.global.u64 temp1, [in_addr];
|
||||||
|
st.shared.u64 [shared_addr], temp1;
|
||||||
|
ld.shared.u64 temp2, [shared_addr];
|
||||||
|
st.global.u64 [out_addr], temp2;
|
||||||
|
ret;
|
||||||
|
}
|
68
ptx/src/test/spirv_run/shared_ptr_take_address.spvtxt
Normal file
68
ptx/src/test/spirv_run/shared_ptr_take_address.spvtxt
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
OpCapability GenericPointer
|
||||||
|
OpCapability Linkage
|
||||||
|
OpCapability Addresses
|
||||||
|
OpCapability Kernel
|
||||||
|
OpCapability Int8
|
||||||
|
OpCapability Int16
|
||||||
|
OpCapability Int64
|
||||||
|
OpCapability Float16
|
||||||
|
OpCapability Float64
|
||||||
|
%33 = OpExtInstImport "OpenCL.std"
|
||||||
|
OpMemoryModel Physical64 OpenCL
|
||||||
|
OpEntryPoint Kernel %2 "shared_ptr_take_address" %1
|
||||||
|
OpDecorate %1 Alignment 4
|
||||||
|
%void = OpTypeVoid
|
||||||
|
%uchar = OpTypeInt 8 0
|
||||||
|
%_ptr_Workgroup_uchar = OpTypePointer Workgroup %uchar
|
||||||
|
%_ptr_Workgroup__ptr_Workgroup_uchar = OpTypePointer Workgroup %_ptr_Workgroup_uchar
|
||||||
|
%1 = OpVariable %_ptr_Workgroup__ptr_Workgroup_uchar Workgroup
|
||||||
|
%ulong = OpTypeInt 64 0
|
||||||
|
%39 = OpTypeFunction %void %ulong %ulong %_ptr_Workgroup_uchar
|
||||||
|
%_ptr_Function__ptr_Workgroup_uchar = OpTypePointer Function %_ptr_Workgroup_uchar
|
||||||
|
%_ptr_Function_ulong = OpTypePointer Function %ulong
|
||||||
|
%_ptr_CrossWorkgroup_ulong = OpTypePointer CrossWorkgroup %ulong
|
||||||
|
%_ptr_Workgroup_ulong = OpTypePointer Workgroup %ulong
|
||||||
|
%2 = OpFunction %void None %39
|
||||||
|
%10 = OpFunctionParameter %ulong
|
||||||
|
%11 = OpFunctionParameter %ulong
|
||||||
|
%31 = OpFunctionParameter %_ptr_Workgroup_uchar
|
||||||
|
%40 = OpLabel
|
||||||
|
%32 = OpVariable %_ptr_Function__ptr_Workgroup_uchar Function
|
||||||
|
%3 = OpVariable %_ptr_Function_ulong Function
|
||||||
|
%4 = OpVariable %_ptr_Function_ulong Function
|
||||||
|
%5 = OpVariable %_ptr_Function_ulong Function
|
||||||
|
%6 = OpVariable %_ptr_Function_ulong Function
|
||||||
|
%7 = OpVariable %_ptr_Function_ulong Function
|
||||||
|
%8 = OpVariable %_ptr_Function_ulong Function
|
||||||
|
%9 = OpVariable %_ptr_Function_ulong Function
|
||||||
|
OpStore %32 %31
|
||||||
|
OpBranch %29
|
||||||
|
%29 = OpLabel
|
||||||
|
OpStore %3 %10
|
||||||
|
OpStore %4 %11
|
||||||
|
%12 = OpLoad %ulong %3
|
||||||
|
OpStore %5 %12
|
||||||
|
%13 = OpLoad %ulong %4
|
||||||
|
OpStore %6 %13
|
||||||
|
%15 = OpLoad %_ptr_Workgroup_uchar %32
|
||||||
|
%24 = OpConvertPtrToU %ulong %15
|
||||||
|
%14 = OpCopyObject %ulong %24
|
||||||
|
OpStore %7 %14
|
||||||
|
%17 = OpLoad %ulong %5
|
||||||
|
%25 = OpConvertUToPtr %_ptr_CrossWorkgroup_ulong %17
|
||||||
|
%16 = OpLoad %ulong %25
|
||||||
|
OpStore %8 %16
|
||||||
|
%18 = OpLoad %ulong %7
|
||||||
|
%19 = OpLoad %ulong %8
|
||||||
|
%26 = OpConvertUToPtr %_ptr_Workgroup_ulong %18
|
||||||
|
OpStore %26 %19
|
||||||
|
%21 = OpLoad %ulong %7
|
||||||
|
%27 = OpConvertUToPtr %_ptr_Workgroup_ulong %21
|
||||||
|
%20 = OpLoad %ulong %27
|
||||||
|
OpStore %9 %20
|
||||||
|
%22 = OpLoad %ulong %6
|
||||||
|
%23 = OpLoad %ulong %9
|
||||||
|
%28 = OpConvertUToPtr %_ptr_CrossWorkgroup_ulong %22
|
||||||
|
OpStore %28 %23
|
||||||
|
OpReturn
|
||||||
|
OpFunctionEnd
|
@ -843,8 +843,10 @@ fn replace_uses_of_shared_memory<'a>(
|
|||||||
statement => {
|
statement => {
|
||||||
let new_statement = statement.map_id(&mut |id, _| {
|
let new_statement = statement.map_id(&mut |id, _| {
|
||||||
if let Some(typ) = extern_shared_decls.get(&id) {
|
if let Some(typ) = extern_shared_decls.get(&id) {
|
||||||
|
if *typ == ast::SizedScalarType::B8 {
|
||||||
|
return shared_var_id;
|
||||||
|
}
|
||||||
let replacement_id = new_id();
|
let replacement_id = new_id();
|
||||||
if *typ != ast::SizedScalarType::B8 {
|
|
||||||
result.push(Statement::Conversion(ImplicitConversion {
|
result.push(Statement::Conversion(ImplicitConversion {
|
||||||
src: shared_var_id,
|
src: shared_var_id,
|
||||||
dst: replacement_id,
|
dst: replacement_id,
|
||||||
@ -860,7 +862,6 @@ fn replace_uses_of_shared_memory<'a>(
|
|||||||
src_sema: ArgumentSemantics::Default,
|
src_sema: ArgumentSemantics::Default,
|
||||||
dst_sema: ArgumentSemantics::Default,
|
dst_sema: ArgumentSemantics::Default,
|
||||||
}));
|
}));
|
||||||
}
|
|
||||||
replacement_id
|
replacement_id
|
||||||
} else {
|
} else {
|
||||||
id
|
id
|
||||||
|
Reference in New Issue
Block a user