Skip to content

Conversation

@JaapWijnen
Copy link
Collaborator

This MR adds derivatives to types conforming to RealFunctions such as Float and Double
This also adds RealFunctions conformance to SIMD types and their derivatives.
This is achieved through generating default implementations for the SIMD protocol and also generating concrete implementations that can have derivatives attached to them. This is required since we can't have default derivative implementations for protocol requirements.
Most of the code is generated by a plugin.

@JaapWijnen JaapWijnen force-pushed the feature/realfunctions-derivatives branch 16 times, most recently from fc82a10 to 142f057 Compare May 2, 2025 19:16
JaapWijnen added 2 commits May 2, 2025 13:17
Also adds RealFunctions conformance to SIMD types and their derivatives
@JaapWijnen JaapWijnen force-pushed the feature/realfunctions-derivatives branch from 142f057 to 448b9ce Compare May 2, 2025 19:17
@loonatick-src
Copy link

loonatick-src commented May 7, 2025

Perhaps there should be some tests that use some of the generated functions to have some coverage? Otherwise LGTM

@JaapWijnen
Copy link
Collaborator Author

JaapWijnen commented May 7, 2025

Right, absolutely, good point haha.

Copy link

@tmcdonell tmcdonell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor nits but otherwise LGTM; this is about as good as you can do with stringy codegen. I didn't check the implementation of the vjp`s but assume those are correct (but let's add some tests at some point!)

)
try realFunctionsSIMDExtension.write(to: realFunctionSIMDFileURL, atomically: true, encoding: .utf8)

let floatingPointTypes: [String] = ["Float", "Double"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: there are aliases Float16, Float32, Float64, so you could make this an array of bit widths rather than strings, which might clean up some other parts of the code?

component: "\(floatingPointType)+RealFunctions+Derivatives.swift",
directoryHint: .notDirectory
)
let type = floatingPointType

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ... odd? Is this changing the type from String to something else (in which case annotate it?); or just defining a shorthand name; or ...?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah that was there to match the same structure as around line 65. Removed it now.

@clarkdobson
Copy link

I also didn't check the vjps for correctness, but assuming they're right and we have some basic unit tests, everything looks good to me.

@JaapWijnen
Copy link
Collaborator Author

Happy I added some tests cause I did find two incorrect vjps 😬 copy paste error...

@JaapWijnen JaapWijnen force-pushed the feature/realfunctions-derivatives branch from 4259585 to 8fd0b5a Compare May 8, 2025 08:40
Copy link

@GNMoseke GNMoseke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vjps are out of my wheelhouse but otherwise LGTM

@JaapWijnen JaapWijnen force-pushed the feature/realfunctions-derivatives branch from 4e1643a to 6364866 Compare May 8, 2025 11:46
@JaapWijnen JaapWijnen force-pushed the feature/realfunctions-derivatives branch from 6364866 to 8caa407 Compare May 8, 2025 11:47
@JaapWijnen JaapWijnen merged commit 3329bd5 into main May 8, 2025
5 checks passed
@JaapWijnen JaapWijnen deleted the feature/realfunctions-derivatives branch May 8, 2025 11:55
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.

6 participants