(draft) Unary math cuda kernels#398
Draft
jplauzie wants to merge 1 commit into
Draft
Conversation
unary math cuda kernels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 2, along with #393. 3).
To complement the Time Quantity, here are some unary point wise math Quantity operators, that act on Quantities similar to Div, Mul, etc. This should allow a user to build up arbitrary functions f(x,y,z,t). To pick functions, I just went through the list of existing mumax3 math functions and grabbed ones that seemed likely to be used, and wrapped them into cuda kernels. All of the math functions I included had built in cuda functions except heaviside, so this is mostly just boilerplate to wrap them. The current list of functions is: sin, cos, tan, exp, log, abs, acos, acosh, asin, asinh, atan, atanh, cosh, sinh, tanh, erf, erfc, gamma, heaviside, pow, mul, atan2.
To avoid colliding with existing math functions, I just stuck a Q on it for 'Quantity', but maybe there's a better naming scheme.
I can always add/remove some functions, and there's also the possibility of adding any fused kernels if any seem particularly useful.
I didn't include the PTX/wrapper_go files, apologies. If this gets merged, do you mind generating them? I'm still on a 10 series card, so I don't think I can generate it for the latest 50 series (Windows also seems to change the line endings from LR to CLRF compared to Linux)
For some functions like pow, there are some choices about what to do if an input value is outside of the domain of the function. For now, I just followed what Div does, and it returns 0. This affects acos,acosh,asin,asinh,atanh,gamma. Tan might also need protection for poles. Pow also some custom logic so e.g. sqrt(-x) returns -sqrt(x).
Stylistically: in cuda/unary_math.go I didn't quite follow the style of Div/Mul. Would it be better to revert this? I don't mind, it's just more verbose.
Included is a quick test file, that just picks a few random points and compares them to the existing math functions using Custom Quantities. It's kind of janky, saving a bunch of OVFs and loading from them, there is probably a nicer way to do this.