Giter Club home page Giter Club logo

Comments (8)

wsmoses avatar wsmoses commented on June 21, 2024

Do you have a reproducer for this (to be able to separately test and subsequently fix)?

from enzyme.

wsmoses avatar wsmoses commented on June 21, 2024

bumping @dime10 for the reproducer?

from enzyme.

dime10 avatar dime10 commented on June 21, 2024

Hi @wsmoses, apologies for taking a while to get back to your question. I didn't have an easily reproducible test case on hand because enzyme is deeply integrated into our own compiler package.

I managed to distill something down to the following though. It seems related to the use of the custom allocation/free functions, since without them the error is not raised:

; ModuleID = 'LLVMDialectModule'
source_filename = "LLVMDialectModule"

@enzyme_dupnoneed = linkonce constant i8 0
@enzyme_const = linkonce constant i8 0
@__enzyme_function_like_free = local_unnamed_addr global [2 x ptr] [ptr @_mlir_memref_to_llvm_free, ptr @freename]
@freename = linkonce constant [5 x i8] c"free\00"
@dealloc_indices = linkonce constant [3 x i8] c"-1\00"
@__enzyme_allocation_like = local_unnamed_addr global [4 x ptr] [ptr @_mlir_memref_to_llvm_alloc, ptr null, ptr @dealloc_indices, ptr @_mlir_memref_to_llvm_free]

declare void @__enzyme_autodiff0(...) local_unnamed_addr

declare void @_mlir_memref_to_llvm_free(ptr)

declare ptr @_mlir_memref_to_llvm_alloc(i64)

define { ptr, ptr, i64 } @jit_compiled(ptr %0, ptr %1, i64 %2, ptr %3, ptr %4, i64 %5) local_unnamed_addr {
  %7 = tail call ptr @_mlir_memref_to_llvm_alloc(i64 72)
  %8 = ptrtoint ptr %7 to i64
  %9 = add i64 %8, 63
  %10 = and i64 %9, -64
  %11 = inttoptr i64 %10 to ptr
  store double 0.000000e+00, ptr %11, align 64
  %12 = tail call ptr @_mlir_memref_to_llvm_alloc(i64 72)
  %13 = ptrtoint ptr %12 to i64
  %14 = add i64 %13, 63
  %15 = and i64 %14, -64
  %16 = inttoptr i64 %15 to ptr
  %17 = load i64, ptr %11, align 64
  store i64 %17, ptr %16, align 64
  tail call void @_mlir_memref_to_llvm_free(ptr %7)
  store double 1.000000e+00, ptr %16, align 64
  %18 = tail call ptr @_mlir_memref_to_llvm_alloc(i64 8)
  %19 = tail call ptr @_mlir_memref_to_llvm_alloc(i64 8)
  %20 = tail call ptr @_mlir_memref_to_llvm_alloc(i64 8)
  %21 = load i64, ptr %16, align 64
  store i64 %21, ptr %20, align 1
  tail call void @_mlir_memref_to_llvm_free(ptr %12)
  store i64 0, ptr %18, align 1
  tail call void (...) @__enzyme_autodiff0(ptr nonnull @f_compiled.preprocess, ptr nonnull @enzyme_const, ptr %0, ptr %1, ptr nonnull %18, i64 %2, ptr nonnull @enzyme_const, ptr %3, ptr nonnull @enzyme_const, ptr %4, i64 %5, ptr nonnull @enzyme_const, i64 1, ptr nonnull @enzyme_const, ptr %19, ptr nonnull @enzyme_dupnoneed, ptr %19, ptr nonnull %20, i64 0)
  tail call void @_mlir_memref_to_llvm_free(ptr nonnull %20)
  tail call void @_mlir_memref_to_llvm_free(ptr %19)
  %22 = icmp eq ptr %18, inttoptr (i64 3735928559 to ptr)
  br i1 %22, label %23, label %26

23:                                               ; preds = %6
  %24 = tail call ptr @_mlir_memref_to_llvm_alloc(i64 8)
  %25 = load i64, ptr inttoptr (i64 3735928559 to ptr), align 1
  store i64 %25, ptr %24, align 1
  br label %26

26:                                               ; preds = %23, %6
  %.pn3 = phi ptr [ %24, %23 ], [ %18, %6 ]
  %.pn2 = insertvalue { ptr, ptr, i64 } undef, ptr %.pn3, 0
  %.pn = insertvalue { ptr, ptr, i64 } %.pn2, ptr %.pn3, 1
  %27 = insertvalue { ptr, ptr, i64 } %.pn, i64 0, 2
  ret { ptr, ptr, i64 } %27
}

define void @f_compiled.preprocess(ptr %0, ptr %1, i64 %2, ptr %3, ptr %4, i64 %5, i64 %6, ptr nocapture readnone %7, ptr nocapture writeonly %8, i64 %9) {
  %.idx = shl i64 %6, 3
  %11 = tail call ptr @_mlir_memref_to_llvm_alloc(i64 %.idx)
  %12 = load double, ptr %4, align 8
  %13 = fcmp ogt double %12, 1.500000e+00
  %14 = load double, ptr %1, align 8
  %15 = fmul double %14, 2.000000e+00
  %storemerge = select i1 %13, double %15, double %14
  store double %storemerge, ptr %11, align 8
  %16 = alloca { ptr, ptr, i64 }, align 8
  store ptr %0, ptr %16, align 8
  %.repack2 = getelementptr inbounds { ptr, ptr, i64 }, ptr %16, i64 0, i32 1
  store ptr %1, ptr %.repack2, align 8
  %.repack4 = getelementptr inbounds { ptr, ptr, i64 }, ptr %16, i64 0, i32 2
  store i64 %2, ptr %.repack4, align 8
  %17 = alloca { ptr, ptr, i64 }, align 8
  store ptr %3, ptr %17, align 8
  %.repack6 = getelementptr inbounds { ptr, ptr, i64 }, ptr %17, i64 0, i32 1
  store ptr %4, ptr %.repack6, align 8
  %.repack8 = getelementptr inbounds { ptr, ptr, i64 }, ptr %17, i64 0, i32 2
  store i64 %5, ptr %.repack8, align 8
  %18 = alloca { ptr, ptr, i64, [1 x i64], [1 x i64] }, align 8
  store ptr %11, ptr %18, align 8
  %.repack10 = getelementptr inbounds { ptr, ptr, i64, [1 x i64], [1 x i64] }, ptr %18, i64 0, i32 1
  store ptr %11, ptr %.repack10, align 8
  %.repack12 = getelementptr inbounds { ptr, ptr, i64, [1 x i64], [1 x i64] }, ptr %18, i64 0, i32 2
  store i64 0, ptr %.repack12, align 8
  %.repack14 = getelementptr inbounds { ptr, ptr, i64, [1 x i64], [1 x i64] }, ptr %18, i64 0, i32 3
  store i64 %6, ptr %.repack14, align 8
  %.repack16 = getelementptr inbounds { ptr, ptr, i64, [1 x i64], [1 x i64] }, ptr %18, i64 0, i32 4
  store i64 1, ptr %.repack16, align 8
  %19 = tail call ptr @_mlir_memref_to_llvm_alloc(i64 8)
  %20 = alloca { ptr, ptr, i64 }, align 8
  store ptr %19, ptr %20, align 8
  %.repack18 = getelementptr inbounds { ptr, ptr, i64 }, ptr %20, i64 0, i32 1
  store ptr %19, ptr %.repack18, align 8
  %.repack20 = getelementptr inbounds { ptr, ptr, i64 }, ptr %20, i64 0, i32 2
  store i64 0, ptr %.repack20, align 8
  ;call void @f_compiled...
  %21 = load double, ptr %19, align 8
  store double %21, ptr %8, align 8
  ret void
}

Invoked with:

LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so) opt -load-pass-plugin=<LLVMEnzyme-18.so> <test_file.ll> -S -passes=enzyme

And I compiled Enzyme with (LLVM compiled w/o asan):

add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)

from enzyme.

dime10 avatar dime10 commented on June 21, 2024

Bumping this for a label update at least, I understand that the issue itself might not be the highest priority.

from enzyme.

wsmoses avatar wsmoses commented on June 21, 2024

Ah I'm sorry I haven't had a chance to reproduce/investigate this yet.

However if you're able to get the asan trace on the current Enzyme main with debug info that would be helpful (as the code there has changed a lot since then)

from enzyme.

wsmoses avatar wsmoses commented on June 21, 2024

Okay I have isolated the issue, and now turned into an assertion. Working on a fix.

from enzyme.

wsmoses avatar wsmoses commented on June 21, 2024

@dime10 this will be fixed by #1700

While I was at it I also added native support for the mlir alloc/free functions, so you don't need to have those done via the global/metadata.

from enzyme.

dime10 avatar dime10 commented on June 21, 2024

Hey @wsmoses, thanks a lot for providing that fix, appreciate it! The builtin recognition of custom malloc/free functions is also a nice touch.

from enzyme.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.