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

Deciding the array size to be used when differentiating VisitCallExpr #242

Closed
sudo-panda opened this issue Jun 8, 2021 · 1 comment
Closed
Assignees
Milestone

Comments

@sudo-panda
Copy link
Contributor

This issue references the PR #237

We need to decide the size temporary array that is build for a CallExpr. For example, when the below function is differentiated:

void f(double *a, double *out) {
  g(a, out);
}

The grad function is:

f_grad(double *a, double *_d_a, double *out) {
    double *_t0;
    double *_t1;
    _t0 = a;
    _t1 = out;
    g(_t0, _t1);
    {
        double _grad0[10] = {};           // This is the array in consideration
        g_grad(_t0, _grad0, _t1);
        double *_r0 = _grad0;
        _d_a = _r0;
        double *_r1;
    }
}

The required size of _grad0 cannot be calculated before differentiating the g function so we need to decide between:

  • Allowing users to set a size by using a macro or an argument
  • Calculating the diff function and determining the size required before declaring the grad array (will take more computation)
@vgvassilev vgvassilev added this to the v1.5 milestone Feb 12, 2024
@PetroZarytskyi
Copy link
Collaborator

This was fixed at some point. The gradient generated on the current master is:

void f_grad(double *a, double *out, clad::array_ref<double> _d_a, clad::array_ref<double> _d_out) {
    g(a, out);
    g_pullback(a, out, _d_a, _d_out);
}

We don't create _grad/_r variables for pointer arguments anymore.
If somebody believes this is not the case, please reopen the issue.

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

No branches or pull requests

3 participants