Skip to content

[SPIRV] Support Bool buffer argument - #7591

Merged
tqchen merged 4 commits into
apache:mainfrom
masahi:spirv-bool-buffer
Mar 5, 2021
Merged

[SPIRV] Support Bool buffer argument#7591
tqchen merged 4 commits into
apache:mainfrom
masahi:spirv-bool-buffer

Conversation

@masahi

@masahi masahi commented Mar 4, 2021

Copy link
Copy Markdown
Member

SPIR-V spec says we cannot physically address boolean buffers, but right now we are generating code like this:

%_runtimearr_bool = OpTypeRuntimeArray %bool
...
%_ptr_StorageBuffer_bool = OpTypePointer StorageBuffer %bool
...
         %36 = OpInBoundsAccessChain %_ptr_StorageBuffer_bool %16 %int_0 %24
         %37 = OpLoad %bool %36 None

This is generating garbage outputs. Actually we hit an error at

int nbits = value_type.type.bits() * value_type.type.lanes();
ICHECK_EQ(nbits % 8, 0);
so boolean buffers are not supported at all.

I updated SPIR-V codegen to make a char buffer when the input is a bool tensor, and add cast to bool after loading the char.

If this change looks good, I should probably update the visitor for storing bool buffer output as well.

This enables running the cumsum test on a boolean flag array, which is explicitly disabled for vulkan in #7572 due to the lack of this fix.

@tqchen @tmoreau89 @jwfromm

@jwfromm jwfromm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks masa!

Comment thread src/target/spirv/codegen_spirv.cc Outdated
Comment thread tests/python/unittest/test_target_codegen_spirv.py Outdated
@masahi

masahi commented Mar 5, 2021

Copy link
Copy Markdown
Member Author

@tqchen please have a look, I'll update #7572 after this is merged, to enable the cumsum test on boolean input.

@tqchen
tqchen merged commit d7f5753 into apache:main Mar 5, 2021
@tqchen

tqchen commented Mar 5, 2021

Copy link
Copy Markdown
Member

Thanks @masahi @jwfromm

trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request May 11, 2021
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.

3 participants