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

Allow custom importing of files and syntactic sugar #1752

Merged
merged 10 commits into from
Feb 27, 2024
Merged

Allow custom importing of files and syntactic sugar #1752

merged 10 commits into from
Feb 27, 2024

Conversation

wsmoses
Copy link
Member

@wsmoses wsmoses commented Feb 22, 2024

No description provided.

@wsmoses
Copy link
Member Author

wsmoses commented Feb 22, 2024

@samuelpmishLLNL @samuelpmish the syntactic sugar is now functional and added ehre (and tested).

@ivanradanov
Copy link
Collaborator

ivanradanov commented Feb 22, 2024

@wsmoses What do you think about having the tblgen entries be input filename - output filename pairs (e.g. enzyme/enzyme.in -> enzyme/enzyme) and then we can have the contents of the headers in separate files which will be valid C/C++ (would be better for editing)

I can try to implement that if you think it is better

@ivanradanov
Copy link
Collaborator

ivanradanov commented Feb 26, 2024

@wsmoses
I have not figured out what exactly happens but there seems to be a bug somewhere either in clang/llvm or the autodiff/tuple templates as the sugar.cpp test ends up with something like:

define linkonce_odr dso_local { double, double } @_ZN6enzyme8autodiffIRFdddEJRNS_6activeIdEES5_EEEDaOT_DpOT0_(ptr noundef nonnull %f, ptr noundef nonnull align 8 dereferenceable(8) %args, ptr noundef nonnull align 8 dereferenceable(8) %args1) local_unnamed_addr #4 comdat {
entry:
  %ref.tmp = alloca %"struct.enzyme::tuple.1", align 8
  %ref.tmp3 = alloca %"struct.enzyme::tuple.6", align 8
  %ref.tmp4 = alloca %"struct.enzyme::tuple.6", align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %ref.tmp) #11
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %ref.tmp3) #11
  %0 = load i32, ptr @enzyme_out, align 4, !tbaa !5
  %1 = load double, ptr %args, align 8, !tbaa !9
  %.fca.0.insert.i = insertvalue { i32, double } poison, i32 %0, 0
  %.fca.1.insert.i = insertvalue { i32, double } %.fca.0.insert.i, double %1, 1
  %2 = extractvalue { i32, double } %.fca.1.insert.i, 0
  store i32 %2, ptr %ref.tmp3, align 8
  %3 = getelementptr inbounds { i32, double }, ptr %ref.tmp3, i64 0, i32 1
  %4 = extractvalue { i32, double } %.fca.1.insert.i, 1
  store double %4, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %ref.tmp4) #11
  %5 = load i32, ptr @enzyme_out, align 4, !tbaa !5
  %6 = load double, ptr %args1, align 8, !tbaa !9
  %.fca.0.insert.i10 = insertvalue { i32, double } poison, i32 %5, 0
  %.fca.1.insert.i11 = insertvalue { i32, double } %.fca.0.insert.i10, double %6, 1
  %7 = extractvalue { i32, double } %.fca.1.insert.i11, 0
  store i32 %7, ptr %ref.tmp4, align 8
  %8 = getelementptr inbounds { i32, double }, ptr %ref.tmp4, i64 0, i32 1
  %9 = extractvalue { i32, double } %.fca.1.insert.i11, 1
  store double %9, ptr %8, align 8
  %10 = load i32, ptr %ref.tmp, align 8, !tbaa !5
  %add.ptr.i.i.i = getelementptr inbounds i8, ptr %ref.tmp, i64 8
  %11 = load double, ptr %add.ptr.i.i.i, align 8, !tbaa !12
  %add.ptr.i9.i.i = getelementptr inbounds i8, ptr %ref.tmp, i64 16
  %12 = load i32, ptr %add.ptr.i9.i.i, align 8, !tbaa !5
  %add.ptr.i10.i.i = getelementptr inbounds i8, ptr %ref.tmp, i64 24
  %13 = load double, ptr %add.ptr.i10.i.i, align 8, !tbaa !12
  %call4.i.i = call { double, double } @_Z17__enzyme_autodiffIN6enzyme5tupleIJddEEEJPvididEET_DpT0_(ptr noundef nonnull %f, i32 noundef %10, double noundef %11, i32 noundef %12, double noundef %13)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %ref.tmp4) #11
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %ref.tmp3) #11
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %ref.tmp) #11
  ret { double, double } %call4.i.i

Which becomes

  %call4.i.i = call { double, double } @_Z17__enzyme_autodiffIN6enzyme5tupleIJddEEEJPvididEET_DpT0_(ptr noundef nonnull %f, i32 noundef undef, double noundef undef, i32 noundef undef, double noundef undef)

Note the undefs.

@ivanradanov
Copy link
Collaborator

That fixed it on my side

@wsmoses wsmoses merged commit ca06ef3 into main Feb 27, 2024
45 of 46 checks passed
@wsmoses wsmoses deleted the incsroa branch February 27, 2024 06:16
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

Successfully merging this pull request may close these issues.

2 participants