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

Generic math interface #706

Open
4 tasks
njansson opened this issue Nov 7, 2022 · 6 comments
Open
4 tasks

Generic math interface #706

njansson opened this issue Nov 7, 2022 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@njansson
Copy link
Collaborator

njansson commented Nov 7, 2022

Add a generic math interface for all kinds of backends.

@njansson njansson created this issue from a note in Neko v0.5.0 release (To do) Nov 7, 2022
@njansson njansson self-assigned this Nov 7, 2022
@njansson njansson added the enhancement New feature or request label Nov 7, 2022
@njansson njansson added this to the v0.5.0 milestone Nov 7, 2022
@njansson njansson removed this from To do in Neko v0.5.0 release Nov 8, 2022
@njansson njansson removed this from the v0.5.0 milestone Nov 8, 2022
@njansson
Copy link
Collaborator Author

njansson commented Nov 8, 2022

The generic interface prevented inline of the small leaf routines in math.f90, thus gave a quite large performance hit.
Remove from v0.5.0 (https://github.com/ExtremeFLOW/neko/projects/21).

@timofeymukha
Copy link
Collaborator

@njansson As a small comment, we mostly used cpu and not host as far as naming goes so far, like in bcknd folders.

@timofeymukha
Copy link
Collaborator

@njansson I wonder if we can also use assumed shape arrays in math, so that one does not have to specify the size in stuff like rzero. I guess the size is always the whole array. I just had a very nasty bug, where I passed a value, which was to high, and the array was a part of a type. So it went over to other attributes in memory and zeroed them out :P. Was pretty damn hard to find.

@timofeymukha
Copy link
Collaborator

timofeymukha commented Apr 28, 2024

@njansson How about a poor man's generic interface, which is just

subroutine rzero(x, n)

if (NEKO_BCKND_DEVICE .eq. 1) then
   x_d = device_get_ptr(x)
   call device_rzero(x_d, n)
else
   call cpu_rzero(x, n)
end
end

This should not affect performance I suppose since this is exactly what we do all over the code? It would still clean up a lot of if-statements!

@njansson
Copy link
Collaborator Author

@njansson How about a poor man's generic interface, which is just

subroutine rzero(x, n)

if (NEKO_BCKND_DEVICE .eq. 1) then
   x_d = device_get_ptr(x)
   call device_rzero(x_d, n)
else
   call cpu_rzero(x, n)
end
end

This should not affect performance I suppose since this is exactly what we do all over the code? It would still clean up a lot of if-statements!

Since device_** calls are quite expensive due to its overhead vs compute time, the additional pointer lookup adds a bit too much I would say. Furthermore, for CPU backends it the if statement will introduce the same issue with inlining as the generic interfaces :( This can of course be solved by writing out the loops where we would like inlining (which also allow for fusing). Then we add the generic interface without too much performance loss across the backends, and also add openmp for cpus.

@njansson
Copy link
Collaborator Author

Maybe a bit clearer, I would suggest we take the approach of feature/omp for the main part of our current math usage. Add the generic interface, which would then only be used in "less" performance critical part of the code. This would also be a great improvement for the user when writing user files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants