Skip to content

Commit aa9e7d6

Browse files
committed
Fix warnings previously hidden by manual builds through enzyme_add_executable CMake macro.
1 parent e888e23 commit aa9e7d6

6 files changed

Lines changed: 69 additions & 69 deletions

File tree

examples/Enzyme/Library/Vector/EnzymeVector.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ inline double dsquare_ref_scalar(double x)
2020
DenseMatrix dsquare_ref(std::vector<double> x, std::vector<double> y)
2121
{
2222
DenseMatrix jac(x.size(), y.size());
23-
for (int idy = 0; idy < y.size(); ++idy)
23+
for (size_t idy = 0; idy < y.size(); ++idy)
2424
{
25-
for (int idx = 0; idx < x.size(); ++idx)
25+
for (size_t idx = 0; idx < x.size(); ++idx)
2626
{
2727
if (idy <= idx)
2828
jac.setValue(idx, idy, dsquare_ref_scalar(x[idy]));
@@ -34,12 +34,12 @@ DenseMatrix dsquare_ref(std::vector<double> x, std::vector<double> y)
3434
int main()
3535
{
3636
// Size and variable declarations
37-
constexpr int n = 10;
37+
constexpr size_t n = 10;
3838
std::vector<double> var(n);
3939

4040
// Random input values
41-
srand(time(NULL));
42-
for (int idx = 0; idx < var.size(); ++idx)
41+
srand(static_cast<unsigned int>(time(NULL)));
42+
for (size_t idx = 0; idx < var.size(); ++idx)
4343
{
4444
var[idx] = rand();
4545
}
@@ -59,9 +59,9 @@ int main()
5959
// Check
6060
int fail = 0;
6161
bool verbose = true;
62-
for (int idy = 0; idy < res.size(); ++idy)
62+
for (size_t idy = 0; idy < res.size(); ++idy)
6363
{
64-
for (int idx = 0; idx < var.size(); ++idx)
64+
for (size_t idx = 0; idx < var.size(); ++idx)
6565
{
6666
if (std::abs(jac.getValue(idx, idy) - jac_ref.getValue(idx, idy)) > std::numeric_limits<double>::epsilon())
6767
{

examples/Enzyme/Library/Vector/VectorModel.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "EnzymeWrapper.hpp"
66

7-
VectorModel::VectorModel(int n)
7+
VectorModel::VectorModel(size_t n)
88
: x_(n),
99
f_(n),
1010
df_dx_(n, n)
@@ -18,10 +18,10 @@ inline double VectorModel::square_scalar(double x)
1818

1919
void VectorModel::square(std::vector<double>& x, std::vector<double>& y)
2020
{
21-
for (int idx = 0; idx < x.size(); ++idx)
21+
for (size_t idx = 0; idx < x.size(); ++idx)
2222
{
2323
y[idx] = 0.0;
24-
for (int idy = 0; idy <= idx; idy++)
24+
for (size_t idy = 0; idy <= idx; idy++)
2525
{
2626
y[idx] += this->square_scalar(x[idy]);
2727
}
@@ -30,7 +30,7 @@ void VectorModel::square(std::vector<double>& x, std::vector<double>& y)
3030

3131
void VectorModel::setVariable(std::vector<double> x)
3232
{
33-
for (int idx = 0; idx < x.size(); ++idx)
33+
for (size_t idx = 0; idx < x.size(); ++idx)
3434
{
3535
x_[idx] = x[idx];
3636
}
@@ -43,13 +43,13 @@ void VectorModel::evalResidual()
4343

4444
void VectorModel::evalJacobian()
4545
{
46-
const int n = x_.size();
46+
const size_t n = x_.size();
4747
std::vector<double> v(n);
4848
VectorModel d_vector_model(n);
49-
for (int idy = 0; idy < n; ++idy)
49+
for (size_t idy = 0; idy < n; ++idy)
5050
{
5151
// Elementary vector for Jacobian-vector product
52-
for (int idx = 0; idx < n; ++idx)
52+
for (size_t idx = 0; idx < n; ++idx)
5353
{
5454
v[idx] = 0.0;
5555
}
@@ -64,7 +64,7 @@ void VectorModel::evalJacobian()
6464
&d_vector_model);
6565

6666
// Store result
67-
for (int idx = 0; idx < n; ++idx)
67+
for (size_t idx = 0; idx < n; ++idx)
6868
{
6969
df_dx_.setValue(idx, idy, d_res[idx]);
7070
}

examples/Enzyme/Library/Vector/VectorModel.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class VectorModel
1717
void square(std::vector<double>&, std::vector<double>&);
1818

1919
public:
20-
VectorModel(int);
20+
VectorModel(size_t);
2121
void setVariable(std::vector<double>);
2222
void evalResidual();
2323
void evalJacobian();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
add_executable(EnzymePowerElectronicsCheck main.cpp)
2-
target_compile_options(EnzymePowerElectronicsCheck PUBLIC -O2 -fno-vectorize -ffast-math -fno-unroll-loops)
2+
target_compile_options(EnzymePowerElectronicsCheck PUBLIC -fno-vectorize -ffast-math -fno-unroll-loops)
33
target_link_libraries(EnzymePowerElectronicsCheck ClangEnzymeFlags GRIDKIT::DenseMatrix GRIDKIT::power_elec_disgen)
44

55
add_test(NAME "EnzymePowerElectronicsCheck" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EnzymePowerElectronicsCheck)

examples/Enzyme/Standalone/EnzymeSparse.cpp

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,66 +26,66 @@ template <typename T, typename... Tys>
2626
extern T __enzyme_todense(Tys...) noexcept;
2727

2828
/// Sparse storage for Enzyme
29-
template <typename T>
29+
template <typename ScalarT>
3030
struct Triple
3131
{
32-
size_t row;
33-
size_t col;
34-
T val;
32+
size_t row;
33+
size_t col;
34+
ScalarT val;
3535
Triple(Triple&&) = default;
3636

37-
Triple(size_t row, size_t col, T val)
37+
Triple(size_t row, size_t col, ScalarT val)
3838
: row(row),
3939
col(col),
4040
val(val)
4141
{
4242
}
4343
};
4444

45-
__attribute__((enzyme_sparse_accumulate)) static void inner_storeflt(int64_t row, int64_t col, float val, std::vector<Triple<float>>& triplets)
45+
[[maybe_unused]] __attribute__((enzyme_sparse_accumulate)) static void inner_storeflt(size_t row, size_t col, float val, std::vector<Triple<float>>& triplets)
4646
{
4747
triplets.emplace_back(row, col, val);
4848
}
4949

50-
__attribute__((enzyme_sparse_accumulate)) static void inner_storedbl(int64_t row, int64_t col, double val, std::vector<Triple<double>>& triplets)
50+
[[maybe_unused]] __attribute__((enzyme_sparse_accumulate)) static void inner_storedbl(size_t row, size_t col, double val, std::vector<Triple<double>>& triplets)
5151
{
5252
triplets.emplace_back(row, col, val);
5353
}
5454

55-
template <typename T>
56-
__attribute__((always_inline)) static void sparse_store(T val, int64_t idx, size_t i, std::vector<Triple<T>>& triplets)
55+
template <typename ScalarT>
56+
__attribute__((always_inline)) static void sparse_store(ScalarT val, size_t idx, size_t i, std::vector<Triple<ScalarT>>& triplets)
5757
{
5858
if (val == 0.0)
5959
return;
60-
idx /= sizeof(T);
61-
if constexpr (sizeof(T) == 4)
60+
idx /= sizeof(ScalarT);
61+
if constexpr (sizeof(ScalarT) == 4)
6262
inner_storeflt(idx, i, val, triplets);
6363
else
6464
inner_storedbl(idx, i, val, triplets);
6565
}
6666

67-
template <typename T>
68-
__attribute__((always_inline)) static T sparse_load(int64_t idx, size_t i, std::vector<Triple<T>>& triplets)
67+
template <typename ScalarT>
68+
__attribute__((always_inline)) static ScalarT sparse_load(size_t, size_t, std::vector<Triple<ScalarT>>&)
6969
{
7070
return 0.0;
7171
}
7272

73-
template <typename T>
74-
__attribute__((always_inline)) static void ident_store(T, int64_t idx, size_t i)
73+
template <typename ScalarT>
74+
__attribute__((always_inline)) static void ident_store(ScalarT, size_t, size_t)
7575
{
7676
assert(0 && "should never load");
7777
}
7878

79-
template <typename T>
80-
__attribute__((always_inline)) static T ident_load(int64_t idx, size_t i)
79+
template <typename ScalarT>
80+
__attribute__((always_inline)) static ScalarT ident_load(size_t idx, size_t i)
8181
{
82-
idx /= sizeof(T);
83-
return (T) (idx == i);
82+
idx /= sizeof(ScalarT);
83+
return (ScalarT) (idx == i);
8484
}
8585

8686
/// Vector-valued function to differentiate
87-
template <typename T>
88-
__attribute__((always_inline)) static void f(size_t N, T* input, T* output)
87+
template <typename ScalarT>
88+
__attribute__((always_inline)) static void f(size_t N, ScalarT* input, ScalarT* output)
8989
{
9090
for (size_t idx = 0; idx < N; ++idx)
9191
{
@@ -98,15 +98,15 @@ __attribute__((always_inline)) static void f(size_t N, T* input, T* output)
9898
}
9999

100100
/// Reference Jacobian
101-
template <typename T>
102-
void jac_f_ref(std::vector<T> x, std::vector<T> y, SparseMatrix& jac)
101+
template <typename ScalarT>
102+
void jac_f_ref(std::vector<ScalarT> x, std::vector<ScalarT> y, SparseMatrix& jac)
103103
{
104-
std::vector<size_t> ctemp{};
105-
std::vector<size_t> rtemp{};
106-
std::vector<T> valtemp{};
107-
for (int idy = 0; idy < y.size(); ++idy)
104+
std::vector<size_t> ctemp{};
105+
std::vector<size_t> rtemp{};
106+
std::vector<ScalarT> valtemp{};
107+
for (size_t idy = 0; idy < y.size(); ++idy)
108108
{
109-
for (int idx = 0; idx < x.size(); ++idx)
109+
for (size_t idx = 0; idx < x.size(); ++idx)
110110
{
111111
if (idy <= idx)
112112
{
@@ -120,29 +120,29 @@ void jac_f_ref(std::vector<T> x, std::vector<T> y, SparseMatrix& jac)
120120
}
121121

122122
/// Function that computes the Jacobian via automatic differentiation
123-
template <typename T>
124-
__attribute__((noinline)) void jac_f(size_t N, T* input, SparseMatrix& jac)
123+
template <typename ScalarT>
124+
__attribute__((noinline)) void jac_f(size_t N, ScalarT* input, SparseMatrix& jac)
125125
{
126-
std::vector<Triple<T>> triplets;
126+
std::vector<Triple<ScalarT>> triplets;
127127
for (size_t i = 0; i < N; i++)
128128
{
129-
T* output = __enzyme_todense<T*>((void*) ident_load<T>, (void*) ident_store<T>, i);
130-
T* d_output = __enzyme_todense<T*>((void*) sparse_load<T>, (void*) sparse_store<T>, i, &triplets);
129+
ScalarT* output = __enzyme_todense<ScalarT*>((void*) ident_load<ScalarT>, (void*) ident_store<ScalarT>, i);
130+
ScalarT* d_output = __enzyme_todense<ScalarT*>((void*) sparse_load<ScalarT>, (void*) sparse_store<ScalarT>, i, &triplets);
131131

132-
__enzyme_fwddiff<void>((void*) f<T>,
132+
__enzyme_fwddiff<void>((void*) f<ScalarT>,
133133
enzyme_const,
134134
N,
135135
enzyme_dup,
136136
input,
137137
output,
138138
enzyme_dupnoneed,
139-
(T*) 0x1,
139+
(ScalarT*) 0x1,
140140
d_output);
141141
}
142142

143-
std::vector<size_t> ctemp{};
144-
std::vector<size_t> rtemp{};
145-
std::vector<T> valtemp{};
143+
std::vector<size_t> ctemp{};
144+
std::vector<size_t> rtemp{};
145+
std::vector<ScalarT> valtemp{};
146146
for (auto& tup : triplets)
147147
{
148148
rtemp.push_back(tup.row);
@@ -159,7 +159,7 @@ void check(SparseMatrix matrix_1, SparseMatrix matrix_2, int& fail)
159159
const auto [rcord_1, ccord_1, vals_1] = entries_1;
160160
std::tuple<std::vector<size_t>&, std::vector<size_t>&, std::vector<double>&> entries_2 = matrix_2.getEntries();
161161
const auto [rcord_2, ccord_2, vals_2] = entries_2;
162-
for (int ind = 0; ind < vals_1.size(); ++ind)
162+
for (size_t ind = 0; ind < vals_1.size(); ++ind)
163163
{
164164
if (rcord_1[ind] != rcord_2[ind])
165165
fail++;
@@ -181,7 +181,7 @@ int main()
181181

182182
/// Input initialization
183183
double val = 0.0;
184-
for (int i = 0; i < N; ++i)
184+
for (size_t i = 0; i < N; ++i)
185185
{
186186
x[i] = val;
187187
val += 1.0;

examples/Enzyme/Standalone/EnzymeVector.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ inline double dsquare_ref_scalar(double x)
3030
// Vector-valued function to differentiate
3131
void square(std::vector<double> x, std::vector<double>& y)
3232
{
33-
for (int idx = 0; idx < x.size(); ++idx)
33+
for (size_t idx = 0; idx < x.size(); ++idx)
3434
{
3535
y[idx] = 0.0;
36-
for (int idy = 0; idy <= idx; idy++)
36+
for (size_t idy = 0; idy <= idx; idy++)
3737
{
3838
y[idx] += square_scalar(x[idy]);
3939
}
@@ -43,9 +43,9 @@ void square(std::vector<double> x, std::vector<double>& y)
4343
// Reference Jacobian
4444
void dsquare_ref(std::vector<double> x, std::vector<double> y, DenseMatrix& dy)
4545
{
46-
for (int idy = 0; idy < y.size(); ++idy)
46+
for (size_t idy = 0; idy < y.size(); ++idy)
4747
{
48-
for (int idx = 0; idx < x.size(); ++idx)
48+
for (size_t idx = 0; idx < x.size(); ++idx)
4949
{
5050
if (idy <= idx)
5151
dy.setValue(idx, idy, dsquare_ref_scalar(x[idy]));
@@ -58,10 +58,10 @@ void dsquare(std::vector<double> x, std::vector<double> y, DenseMatrix& dy)
5858
{
5959
std::vector<double> v(x.size());
6060
std::vector<double> d_y(y.size());
61-
for (int idy = 0; idy < y.size(); ++idy)
61+
for (size_t idy = 0; idy < y.size(); ++idy)
6262
{
6363
// Elementary vector for Jacobian-vector product
64-
for (int idx = 0; idx < x.size(); ++idx)
64+
for (size_t idx = 0; idx < x.size(); ++idx)
6565
{
6666
v[idx] = 0.0;
6767
}
@@ -71,7 +71,7 @@ void dsquare(std::vector<double> x, std::vector<double> y, DenseMatrix& dy)
7171
__enzyme_fwddiff((void*) square, enzyme_dup, x, v, enzyme_dupnoneed, y, &d_y);
7272

7373
// Store result
74-
for (int idx = 0; idx < x.size(); ++idx)
74+
for (size_t idx = 0; idx < x.size(); ++idx)
7575
{
7676
dy.setValue(idx, idy, d_y[idx]);
7777
}
@@ -81,15 +81,15 @@ void dsquare(std::vector<double> x, std::vector<double> y, DenseMatrix& dy)
8181
int main()
8282
{
8383
// Vector and matrix declarations
84-
constexpr int N = 10;
84+
constexpr size_t N = 10;
8585
std::vector<double> x(N);
8686
std::vector<double> sq(N);
8787
DenseMatrix dsq = DenseMatrix(N, N);
8888
DenseMatrix dsq_ref = DenseMatrix(N, N);
8989

9090
// Random input values
91-
srand(time(NULL));
92-
for (int idx = 0; idx < x.size(); ++idx)
91+
srand(static_cast<unsigned int>(time(NULL)));
92+
for (size_t idx = 0; idx < x.size(); ++idx)
9393
{
9494
x[idx] = rand();
9595
}
@@ -106,9 +106,9 @@ int main()
106106
// Check
107107
int fail = 0;
108108
bool verbose = true;
109-
for (int idy = 0; idy < sq.size(); ++idy)
109+
for (size_t idy = 0; idy < sq.size(); ++idy)
110110
{
111-
for (int idx = 0; idx < x.size(); ++idx)
111+
for (size_t idx = 0; idx < x.size(); ++idx)
112112
{
113113
if (std::abs(dsq.getValue(idx, idy) - dsq_ref.getValue(idx, idy)) > std::numeric_limits<double>::epsilon())
114114
{

0 commit comments

Comments
 (0)