-
Notifications
You must be signed in to change notification settings - Fork 145
Open
Description
Hi, I have the following minimal code example:
#include <cmath>
#include <print>
#include <Eigen/Dense> // 3.4.0
#include <enzyme/enzyme>
struct Objective {
double operator()(const double x) const {
Eigen::VectorXd y = Eigen::VectorXd::Zero(2);
y[0] = std::exp(x);
return y.sum();
}
};
int main() {
const auto result = enzyme::autodiff<enzyme::ReverseWithPrimal>(Objective{}, enzyme::Active(1.0));
const auto g = enzyme::get<0>(result);
const auto v = enzyme::get<1>(result);
std::println("value: {}", v);
std::println("g(0): {}", enzyme::get<0>(g));
}I can produce different sets of warnings with different compiler flags e.g.:
clang++ -DEIGEN_DONT_VECTORIZE -isystem /usr/include/eigen3 -O3 -DNDEBUG -std=c++23 -fplugin=/home/jeff/.local/lib/ClangEnzyme-20.so enzyme_issue.cpp
unknown tbaa call instruction user inst: %17 = call double @exp(double noundef %1) #33, !tbaa !13 vdptr: {[]:Pointer, [-1]:Integer}
unknown tbaa call instruction user inst: %24 = call double @exp(double noundef %1) #33, !tbaa !13 vdptr: {[]:Pointer, [-1]:Integer}
unknown tbaa call instruction user inst: %12 = call double @exp(double noundef %1) #34, !tbaa !13 vdptr: {[]:Pointer, [-1]:Integer}
unknown tbaa call instruction user inst: %19 = call double @exp(double noundef %1) #34, !tbaa !13 vdptr: {[]:Pointer, [-1]:Integer}
freeing without malloc %18 = load ptr, ptr %0, align 8, !tbaa !14
freeing without malloc %18 = load ptr, ptr %0, align 8, !tbaa !14
freeing without malloc %33 = phi ptr [ %17, %15 ], [ %11, %10 ], [ %17, %31 ]
clang++ -DEIGEN_DONT_VECTORIZE -isystem /usr/include/eigen3 -O3 -std=c++23 -fplugin=/home/jeff/.local/lib/ClangEnzyme-20.so enzyme_issue.cpp
unknown tbaa call instruction user inst: %3 = tail call double @exp(double noundef %1) #31, !tbaa !5 vdptr: {[]:Pointer, [-1]:Integer}
unknown tbaa call instruction user inst: %3 = tail call double @exp(double noundef %1) #32, !tbaa !5 vdptr: {[]:Pointer, [-1]:Integer}
clang++ -DEIGEN_DONT_VECTORIZE -isystem /usr/include/eigen3 -O3 -DNDEBUG -ffast-math -std=c++23 -fplugin=/home/jeff/.local/lib/ClangEnzyme-20.so enzyme_issue.cpp
freeing without malloc %18 = load ptr, ptr %0, align 8, !tbaa !14
freeing without malloc %18 = load ptr, ptr %0, align 8, !tbaa !14
freeing without malloc %33 = phi ptr [ %17, %15 ], [ %11, %10 ], [ %17, %31 ]
Also if I remove the Eigen::Zeros call, so re-write to something like:
double operator()(const double x) const {
Eigen::VectorXd y(2);
y[0] = std::exp(x);
y[1] = 0.0;
return y.sum();
}then the "freeing without malloc" errors seem to go away.
It would be great to figure out and fix what is happening, or just to get any advice on what to do here.
If there is anything I could do to help with testing etc, please let me know. Thanks!
$ clang++ --version
Ubuntu clang version 20.1.2 (0ubuntu1)
$ git branch # Enzyme checkout
* (HEAD detached at v0.0.203)
Metadata
Metadata
Assignees
Labels
No labels