Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions GridKit/AutomaticDifferentiation/Enzyme/DfDwb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ namespace GridKit
{
if (n_res > 0 && n_var > 0)
{
std::vector<ScalarT> elementary_v(n_var);
for (size_t var_i = 0; var_i < n_var; ++var_i)
{
// Sparse storage. @see LowerSparseStorage.hpp
Expand All @@ -77,11 +76,8 @@ namespace GridKit
vals,
&nnz);

// Elementary vector for Jacobian-vector product
std::ranges::fill(elementary_v, 0.0);
elementary_v[var_i] = 1.0;

// Core automatic differentiation intrinsic that will be replaced by a derivative
// The dummy primal pointer is safe only while residuals never read back their output
__enzyme_fwddiff<void>((void*) ModelWrapper<ModelT, function>::eval,
enzyme_const,
model,
Expand All @@ -91,10 +87,10 @@ namespace GridKit
yp,
enzyme_dup,
wb,
output,
output, // Seed: column var_i of the identity
enzyme_dupnoneed,
elementary_v.data(),
d_output);
(ScalarT*) 0x1, // Unneeded primal residual (dummy pointer)
d_output); // Column var_i of the Jacobian
}
}
}
Expand Down Expand Up @@ -130,7 +126,6 @@ namespace GridKit
{
if (n_res > 0 && n_var > 0)
{
std::vector<ScalarT> elementary_v(n_var);
for (size_t var_i = 0; var_i < n_var; ++var_i)
{
// Sparse storage. @see LowerSparseStorage.hpp
Expand All @@ -148,11 +143,8 @@ namespace GridKit
vals,
&nnz);

// Elementary vector for Jacobian-vector product
std::ranges::fill(elementary_v, 0.0);
elementary_v[var_i] = 1.0;

// Core automatic differentiation intrinsic that will be replaced by a derivative
// The dummy primal pointer is safe only while residuals never read back their output
__enzyme_fwddiff<void>((void*) ModelWrapper<ModelT, function>::eval,
enzyme_const,
model,
Expand All @@ -162,12 +154,12 @@ namespace GridKit
yp,
enzyme_dup,
wb,
output,
output, // Seed: column var_i of the identity
enzyme_const,
ws,
enzyme_dupnoneed,
elementary_v.data(),
d_output);
(ScalarT*) 0x1, // Unneeded primal residual (dummy pointer)
d_output); // Column var_i of the Jacobian
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions GridKit/AutomaticDifferentiation/Enzyme/DfDws.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ namespace GridKit
{
if (n_res > 0 && n_var > 0)
{
std::vector<ScalarT> elementary_v(n_var);
for (size_t var_i = 0; var_i < n_var; ++var_i)
{
// Sparse storage. @see LowerSparseStorage.hpp
Expand All @@ -79,11 +78,8 @@ namespace GridKit
vals,
&nnz);

// Elementary vector for Jacobian-vector product
std::ranges::fill(elementary_v, 0.0);
elementary_v[var_i] = 1.0;

// Core automatic differentiation intrinsic that will be replaced by a derivative
// The dummy primal pointer is safe only while residuals never read back their output
__enzyme_fwddiff<void>((void*) ModelWrapper<ModelT, function>::eval,
enzyme_const,
model,
Expand All @@ -95,10 +91,10 @@ namespace GridKit
wb,
enzyme_dup,
ws,
output,
output, // Seed: column var_i of the identity
enzyme_dupnoneed,
elementary_v.data(),
d_output);
(ScalarT*) 0x1, // Unneeded primal residual (dummy pointer)
d_output); // Column var_i of the Jacobian
}
}
}
Expand Down
24 changes: 8 additions & 16 deletions GridKit/AutomaticDifferentiation/Enzyme/DfDy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ namespace GridKit
{
if (n_res > 0 && n_var > 0)
{
std::vector<ScalarT> elementary_v(n_var);
for (size_t var_i = 0; var_i < n_var; ++var_i)
{
// Sparse storage. @see LowerSparseStorage.hpp
Expand All @@ -77,24 +76,21 @@ namespace GridKit
vals,
&nnz);

// Elementary vector for Jacobian-vector product
std::ranges::fill(elementary_v, 0.0);
elementary_v[var_i] = 1.0;

// Core automatic differentiation intrinsic that will be replaced by a derivative
// The dummy primal pointer is safe only while residuals never read back their output
__enzyme_fwddiff<void>((void*) ModelWrapper<ModelT, function>::eval,
enzyme_const,
model,
enzyme_dup,
y,
output,
output, // Seed: column var_i of the identity
enzyme_const,
yp,
enzyme_const,
wb,
enzyme_dupnoneed,
elementary_v.data(),
d_output);
(ScalarT*) 0x1, // Unneeded primal residual (dummy pointer)
d_output); // Column var_i of the Jacobian
}
}
}
Expand Down Expand Up @@ -130,7 +126,6 @@ namespace GridKit
{
if (n_res > 0 && n_var > 0)
{
std::vector<ScalarT> elementary_v(n_var);
for (size_t var_i = 0; var_i < n_var; ++var_i)
{
// Sparse storage. @see LowerSparseStorage.hpp
Expand All @@ -148,26 +143,23 @@ namespace GridKit
vals,
&nnz);

// Elementary vector for Jacobian-vector product
std::ranges::fill(elementary_v, 0.0);
elementary_v[var_i] = 1.0;

// Core automatic differentiation intrinsic that will be replaced by a derivative
// The dummy primal pointer is safe only while residuals never read back their output
__enzyme_fwddiff<void>((void*) ModelWrapper<ModelT, function>::eval,
enzyme_const,
model,
enzyme_dup,
y,
output,
output, // Seed: column var_i of the identity
enzyme_const,
yp,
enzyme_const,
wb,
enzyme_const,
ws,
enzyme_dupnoneed,
elementary_v.data(),
d_output);
(ScalarT*) 0x1, // Unneeded primal residual (dummy pointer)
d_output); // Column var_i of the Jacobian
}
}
}
Expand Down
24 changes: 8 additions & 16 deletions GridKit/AutomaticDifferentiation/Enzyme/DfDyp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ namespace GridKit
{
if (n_res > 0 && n_var > 0)
{
std::vector<ScalarT> elementary_v(n_var);
for (size_t var_i = 0; var_i < n_var; ++var_i)
{
// Sparse storage. @see LowerSparseStorage.hpp
Expand All @@ -79,24 +78,21 @@ namespace GridKit
vals,
&nnz);

// Elementary vector for Jacobian-vector product
std::ranges::fill(elementary_v, 0.0);
elementary_v[var_i] = 1.0;

// Core automatic differentiation intrinsic that will be replaced by a derivative
// The dummy primal pointer is safe only while residuals never read back their output
__enzyme_fwddiff<void>((void*) ModelWrapper<ModelT, function>::eval,
enzyme_const,
model,
enzyme_const,
y,
enzyme_dup,
yp,
output,
output, // Seed: column var_i of the identity
enzyme_const,
wb,
enzyme_dupnoneed,
elementary_v.data(),
d_output);
(ScalarT*) 0x1, // Unneeded primal residual (dummy pointer)
d_output); // Column var_i of the Jacobian
}
}
}
Expand Down Expand Up @@ -134,7 +130,6 @@ namespace GridKit
{
if (n_res > 0 && n_var > 0)
{
std::vector<ScalarT> elementary_v(n_var);
for (size_t var_i = 0; var_i < n_var; ++var_i)
{
// Sparse storage. @see LowerSparseStorage.hpp
Expand All @@ -152,26 +147,23 @@ namespace GridKit
vals,
&nnz);

// Elementary vector for Jacobian-vector product
std::ranges::fill(elementary_v, 0.0);
elementary_v[var_i] = 1.0;

// Core automatic differentiation intrinsic that will be replaced by a derivative
// The dummy primal pointer is safe only while residuals never read back their output
__enzyme_fwddiff<void>((void*) ModelWrapper<ModelT, function>::eval,
enzyme_const,
model,
enzyme_const,
y,
enzyme_dup,
yp,
output,
output, // Seed: column var_i of the identity
enzyme_const,
wb,
enzyme_const,
ws,
enzyme_dupnoneed,
elementary_v.data(),
d_output);
(ScalarT*) 0x1, // Unneeded primal residual (dummy pointer)
d_output); // Column var_i of the Jacobian
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions GridKit/AutomaticDifferentiation/Enzyme/DhDwb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ namespace GridKit
{
if (n_res > 0 && n_var > 0)
{
std::vector<ScalarT> elementary_v(n_var);
for (size_t var_i = 0; var_i < n_var; ++var_i)
{
// Sparse storage. @see LowerSparseStorage.hpp
Expand All @@ -77,11 +76,8 @@ namespace GridKit
vals,
&nnz);

// Elementary vector for Jacobian-vector product
std::ranges::fill(elementary_v, 0.0);
elementary_v[var_i] = 1.0;

// Core automatic differentiation intrinsic that will be replaced by a derivative
// The dummy primal pointer is safe only while residuals never read back their output
__enzyme_fwddiff<void>((void*) ModelWrapper<ModelT, function>::eval,
enzyme_const,
model,
Expand All @@ -91,10 +87,10 @@ namespace GridKit
yp,
enzyme_dup,
wb,
output,
output, // Seed: column var_i of the identity
enzyme_dupnoneed,
elementary_v.data(),
d_output);
(ScalarT*) 0x1, // Unneeded primal residual (dummy pointer)
d_output); // Column var_i of the Jacobian
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions GridKit/AutomaticDifferentiation/Enzyme/DhDy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ namespace GridKit
{
if (n_res > 0 && n_var > 0)
{
std::vector<ScalarT> elementary_v(n_var);
for (size_t var_i = 0; var_i < n_var; ++var_i)
{
// Sparse storage. @see LowerSparseStorage.hpp
Expand All @@ -77,24 +76,21 @@ namespace GridKit
vals,
&nnz);

// Elementary vector for Jacobian-vector product
std::ranges::fill(elementary_v, 0.0);
elementary_v[var_i] = 1.0;

// Core automatic differentiation intrinsic that will be replaced by a derivative
// The dummy primal pointer is safe only while residuals never read back their output
__enzyme_fwddiff<void>((void*) ModelWrapper<ModelT, function>::eval,
enzyme_const,
model,
enzyme_dup,
y,
output,
output, // Seed: column var_i of the identity
enzyme_const,
yp,
enzyme_const,
wb,
enzyme_dupnoneed,
elementary_v.data(),
d_output);
(ScalarT*) 0x1, // Unneeded primal residual (dummy pointer)
d_output); // Column var_i of the Jacobian
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions GridKit/AutomaticDifferentiation/Enzyme/LowerSparseStorage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ namespace GridKit
IdxT* rows,
IdxT* cols,
ScalarT* vals,
IdxT& nnz)
IdxT* nnz)
{
if (val == 0.0)
return;
Expand All @@ -226,17 +226,17 @@ namespace GridKit
// this template nightmare is because __attribute__((enzyme_sparse_accumulate)) does not support templates yet
if constexpr (std::is_same<IdxT, size_t>::value)
{
if constexpr (std::is_same<IdxT, float>::value)
inner_store_float_size_t(row, col, val, scaling, row_indices, col_indices, rows, cols, vals, nnz);
if constexpr (std::is_same<ScalarT, float>::value)
inner_store_float_size_t(row, col, val, scaling, row_indices, col_indices, rows, cols, vals, *nnz);
else
inner_store_double_size_t(row, col, val, scaling, row_indices, col_indices, rows, cols, vals, nnz);
inner_store_double_size_t(row, col, val, scaling, row_indices, col_indices, rows, cols, vals, *nnz);
}
else if constexpr (std::is_same<IdxT, long int>::value)
{
if constexpr (std::is_same<IdxT, double>::value)
inner_store_float_long_int(row, col, val, scaling, row_indices, col_indices, rows, cols, vals, nnz);
if constexpr (std::is_same<ScalarT, float>::value)
inner_store_float_long_int(row, col, val, scaling, row_indices, col_indices, rows, cols, vals, *nnz);
else
inner_store_double_long_int(row, col, val, scaling, row_indices, col_indices, rows, cols, vals, nnz);
inner_store_double_long_int(row, col, val, scaling, row_indices, col_indices, rows, cols, vals, *nnz);
}
else
{
Expand Down
Loading