-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pitched allocation example #249
base: stable
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I don't really follow the point you are trying to make with this example.
@dalg24 Thanks for reviewing! : - )
#117 explains in detail. The point is that users sometimes need to fill a 2-D array where each contiguous segment (e.g., row for |
I do not understand how this does what you want with respect to pitched allocations? |
I think the accessor needs to store a pitch or some information that every K elements there are 4 extra bytes or whatever. |
Also your argument with the alignment doesn't make much sense to me. The object can't say that it is 12byte aligned anyway for pitched allocations, since the whole purpose is that for some rows its not. |
Wouldn't this thing do what you want (only posted the relevant parts)? template<class T>
struct pitched_accessor {
int n_every;
int extra_bytes;
using data_handle_type = char*;
pitched_accessor(int n_every_, int extra_bytes_) {
assert(extra_bytes%alignof(T)==0);
}
T& access(const data_handle_type& p, size_t i) {
char* p_offset = p + i*size_of(T) + extra_bytes * (i/n_every);
return *reinterpret_cast<T&>(p_offset);
}
}; Probably could have T* as |
This is the example I wrote for the user question here: kokkos#117 Fixes kokkos#248.
0b4dc78
to
83fee78
Compare
* Consolidate public / private declarations * Use bit_cast (restoring constexpr) if the compiler supports it * Remove unused variable
This is the example I wrote for the user question here: #117
Fixes #248.