Skip to content

How to register gradient metadata? #1749

Answered by wsmoses
davidedelvento asked this question in Q&A
Discussion options

You must be logged in to vote

Here is a corrected version of your code:

#include <stdio.h>
#include <stdlib.h>

// Function to differentiate
double square(double x) {
  return x * x;
}
double custom_diff_square(double x) {
  return x * x;
}

double square_aug(double x) {
    return square(x);
}

double my_custom_diff(double x, double diffret) {
  // let's pretend that this is what I want
  return 3 * x * diffret;
}

void* __enzyme_register_gradient_custom_diff_square[3] = { custom_diff_square,
                                                      square_aug,
                                                      my_custom_diff };

double __enzyme_autodiff(void*, ...);
int enzyme_const, enzyme_dup, enzyme_out;

int main(i…

Replies: 5 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@davidedelvento
Comment options

@wsmoses
Comment options

@wsmoses
Comment options

Answer selected by wsmoses
@davidedelvento
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants