Skip to content
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

Tuning reorder123x321_kernel #14

Open
julietbravo opened this issue Jun 16, 2021 · 7 comments
Open

Tuning reorder123x321_kernel #14

julietbravo opened this issue Jun 16, 2021 · 7 comments
Assignees

Comments

@julietbravo
Copy link
Member

I started on this kernel...

@julietbravo julietbravo self-assigned this Jun 16, 2021
@isazi
Copy link
Collaborator

isazi commented Jun 16, 2021

For this particular kernel, the order of dimensions may matter, because ii and ik are mapped to x and z:

const int idx_out = ii + ij*ni + ik*nj*ni;
const int idx_in = ik + ij*nk + ii*nj*nk;
arr_out[idx_out] = arr_in[idx_in];

In this case best memory bandwidth could be achieved by reading in shared memory, reordering, and then writing to output.

@julietbravo
Copy link
Member Author

Yes, I agree. So far I only did a simple block size tuning, which already makes the kernel almost a factor 2 faster: 951ebd3

@isazi
Copy link
Collaborator

isazi commented Jun 16, 2021

Do you want to try shared memory, or should I do it?

@isazi
Copy link
Collaborator

isazi commented Jun 16, 2021

I did actually write a first (dirty) implementation (in my test branch). I will test it tomorrow and let you know.

@julietbravo
Copy link
Member Author

Yes, please, go ahead :-)

@julietbravo julietbravo changed the title Tuning reorder123_321 kernel Tuning reorder123x321_kernel Jun 16, 2021
@isazi
Copy link
Collaborator

isazi commented Jun 17, 2021

Implemented the shared memory version. Performance is the same as the standard (tuned) version, most probably because the cache behavior is so good. So it does not make sense to use this implementation in practice right now. However, if in the future data size is going to increase, shared memory may be able to outperform the cache.

@benvanwerkhoven
Copy link
Collaborator

I was thinking that we could use the CUB library to make a fast version for this kernel: https://nvlabs.github.io/cub/classcub_1_1_block_exchange.html

CUB has all kinds of optimizations built-in to avoid memory bank conflicts for all kinds of devices, data types, and block sizes, and uses warp shuffle instructions where possible. If you can fit the use case that we have here onto such a block-wide primitive in CUB it's probably the best performing option and you can still tune things like items per thread and thread block dimensions.

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

No branches or pull requests

3 participants