Alpaka: static assert on alignment

Created on 11 Mar 2021  路  7Comments  路  Source: alpaka-group/alpaka

In https://github.com/alpaka-group/alpaka/pull/824/files static assertions related to allocation of more than core::vectorization::defaultAlignment were removed and the code was corrected.

However, in the new file alpaka-0.6.0/include/alpaka/block/shared/st/BlockSharedMemStMember.hpp this static assertion was reintroduced although the following lines seem to handle this allocation correctly:

constexpr std::uint32_t align = static_cast<std::uint32_t>(std::max(TDataAlignBytes, alignof(T))); return (m_allocdBytes / align + (m_allocdBytes % align > 0u)) * align;

I suppose that the static_assert got there only by copy&paste and could/should be removed.

Bug

Most helpful comment

@mknaranja We have still the static assert in version 0.6.1 https://github.com/alpaka-group/alpaka/blob/04b70eeda4c03c8f20574496144eb69c11cfad28/include/alpaka/block/shared/st/detail/BlockSharedMemStMemberImpl.hpp#L148-L150

The problem is that we need to guarantee that your data in shared memory is aligned. Currently, the implementation can only guarantee the alignment for data with an alignment < core::vectorization::defaultAlignment because the pointer for shared memory https://github.com/alpaka-group/alpaka/blob/04b70eeda4c03c8f20574496144eb69c11cfad28/include/alpaka/block/shared/st/detail/BlockSharedMemStMemberImpl.hpp#L162 is aligned to this size.
At the moment we align based on offset relative to the pointer address https://github.com/alpaka-group/alpaka/blob/04b70eeda4c03c8f20574496144eb69c11cfad28/include/alpaka/block/shared/st/detail/BlockSharedMemStMemberImpl.hpp#L146
To allow larger alignment we can not use the offset only, we need to check the address from pointer + offset.

I will make this issue a bug, I thought to use the address instead of the offset to align the data but thought it is not necessary.
Looks like we have now a use case.

I will try to write a fix soon and release it together with alpaka 0.6.1

All 7 comments

Hello @mknaranja , thanks for your report!

I think you are right. @psychocoderHPC it seems that this check may be not part of 0.6.1 already, but I am not 100% sure.

@mknaranja welcome to alpaka and thanks for your bug report.

Which alpaka backend do you use?
Which version of alpaka do you use?
What is the type of T you use to create shared memory for?
What is sizeof(T) and alignof(T) giving you back?

Could you please try if you see the same behavior with the upcoming bugfix release 0.6.1: https://github.com/alpaka-group/alpaka/tree/0.6.1
I assume that your type T you use for declareSharedVar<T,any_id>(acc) has a large alignment. declareSharedVar is the way to allocate shared memory in the kernel, the code you are pointed to where the static assert fails is a fork from one of our developer and looks old. In alpaka 0.5.0 the function name was called declVar<T,any_id>(acc)

Yes, of course it has a large alignment, otherwise the static_assert would not fail.

It is a custom data type with alignof(T)=sizeof(T). It can be of variable length, for instance, sizeof(T)=128.

I'm using alpaka 0.6.0 and I've now seen that this assertion has been removed in 0.6.1.

However, I do not understand the setenece "the code you are pointed to where the static assert fails is a fork from one of our developer and looks old" since this assertion is in the official 0.6.0 release.

Thanks for clarification. You are right, it was in 0.6.0 and arrived there from one long-term branch so we got confused about it. It probably should not have gone into 0.6.0 like that, and so is removed in 0.6.1

However, I do not understand the setenece "the code you are pointed to where the static assert fails is a fork from one of our developer and looks old" since this assertion is in the official 0.6.0 release.

The last time I clicked on your link it was pointing into the fork from Benjamin but maybe I messed up with my 1000 open tabs in the browser.

@mknaranja We have still the static assert in version 0.6.1 https://github.com/alpaka-group/alpaka/blob/04b70eeda4c03c8f20574496144eb69c11cfad28/include/alpaka/block/shared/st/detail/BlockSharedMemStMemberImpl.hpp#L148-L150

The problem is that we need to guarantee that your data in shared memory is aligned. Currently, the implementation can only guarantee the alignment for data with an alignment < core::vectorization::defaultAlignment because the pointer for shared memory https://github.com/alpaka-group/alpaka/blob/04b70eeda4c03c8f20574496144eb69c11cfad28/include/alpaka/block/shared/st/detail/BlockSharedMemStMemberImpl.hpp#L162 is aligned to this size.
At the moment we align based on offset relative to the pointer address https://github.com/alpaka-group/alpaka/blob/04b70eeda4c03c8f20574496144eb69c11cfad28/include/alpaka/block/shared/st/detail/BlockSharedMemStMemberImpl.hpp#L146
To allow larger alignment we can not use the offset only, we need to check the address from pointer + offset.

I will make this issue a bug, I thought to use the address instead of the offset to align the data but thought it is not necessary.
Looks like we have now a use case.

I will try to write a fix soon and release it together with alpaka 0.6.1

@mknaranja Your issue should be fixed with #1282. Could you please try the fix and report back if the issue is solved.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kloppstock picture kloppstock  路  3Comments

ax3l picture ax3l  路  3Comments

BenjaminW3 picture BenjaminW3  路  3Comments

shefmarkh picture shefmarkh  路  4Comments

psychocoderHPC picture psychocoderHPC  路  5Comments