You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, if you pass an existing array to the constructor of an A2D mat/vec, the mat/vec allocates it's own memory and copies the values from the array you supplied. In certain situations it would be useful to have the mat/vec directly use the arrays you've already allocated for the primal value and possibly even the derivatives. This could be useful both for reducing memory usage (e.g in GPU kernels), and in reducing the need to copy out derivative values.
For example:
template<typename T, int N>
voidcomputedfdx(T x[], T dfdx[]){
ADObj<Vec<T,N>> xVec(x); // At this point we have 4 arrays of length N allocated (x, dfdx, xVec.A, and xVec.Ab)
ADObj<T> f;
// Make stack that computes f(x)auto stack = MakeStack(...);
f.bvalue = 1.0;
stack.reverse();
// Copy derivative back into dfdxfor (int ii=0; ii<N;ii++){
dfdx[ii] = xVec.bvalue[ii];
}
}
Could instead be implemented as:
template<typename T, int N>
voidcomputedfdx(T x[], T dfdx[]){
ADObj<Vec<T,N>> xVec(&x, &dfdx); // No additional arrays created here
ADObj<T> f;
// Make stack that computes f(x)auto stack = MakeStack(...);
f.bvalue = 1.0;
stack.reverse();
// No need to copy derivative back into dfdx
}
The text was updated successfully, but these errors were encountered:
Currently, if you pass an existing array to the constructor of an A2D mat/vec, the mat/vec allocates it's own memory and copies the values from the array you supplied. In certain situations it would be useful to have the mat/vec directly use the arrays you've already allocated for the primal value and possibly even the derivatives. This could be useful both for reducing memory usage (e.g in GPU kernels), and in reducing the need to copy out derivative values.
For example:
Could instead be implemented as:
The text was updated successfully, but these errors were encountered: