Skip to content

(draft) Unary math cuda kernels#398

Draft
jplauzie wants to merge 1 commit into
mumax:devfrom
jplauzie:Unary_math_Cuda_Kernels2
Draft

(draft) Unary math cuda kernels#398
jplauzie wants to merge 1 commit into
mumax:devfrom
jplauzie:Unary_math_Cuda_Kernels2

Conversation

@jplauzie
Copy link
Copy Markdown
Contributor

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.

unary math cuda kernels
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

Successfully merging this pull request may close these issues.

1 participant