0
Fork 0
mirror of https://github.com/zml/zml.git synced 2026-11-16 19:11:09 +00:00

unused tensor crashes MLIR bytecode writer #97

Closed
opened 2024-11-20 13:05:09 +00:00 by gwenzek · 0 comments
gwenzek commented 2024-11-20 13:05:09 +00:00 (Migrated from github.com)
test "unused tensor" {
    const zml = @import("zml.zig");
    const platform = zml.testing.env();

    const Local = struct {
        pub fn forward(x: Tensor) Tensor {
            const y = x.addConstant(1);
            _ = y;
            return x;
        }
    };

    const mod = try compileFn(std.testing.allocator, Local.forward, .{ Shape.init(.{ 10 }, .f32) }, platform);
    defer mod.deinit();
}

error:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x0000000100952fb0 test`(anonymous namespace)::BytecodeWriter::writeUseListOrders((anonymous namespace)::EncodingEmitter&, unsigned char&, mlir::ValueRange) + 548
    frame #1: 0x0000000100956b54 test`(anonymous namespace)::BytecodeWriter::writeRegions((anonymous namespace)::EncodingEmitter&, llvm::MutableArrayRef<mlir::Region>)::'lambda'(mlir::Region&)::operator()(mlir::Region&) const + 1636
    frame #2: 0x00000001009529f8 test`(anonymous namespace)::BytecodeWriter::writeOp((anonymous namespace)::EncodingEmitter&, mlir::Operation*) + 3148
    frame #3: 0x0000000100956ba0 test`(anonymous namespace)::BytecodeWriter::writeRegions((anonymous namespace)::EncodingEmitter&, llvm::MutableArrayRef<mlir::Region>)::'lambda'(mlir::Region&)::operator()(mlir::Region&) const + 1712
    frame #4: 0x00000001009529f8 test`(anonymous namespace)::BytecodeWriter::writeOp((anonymous namespace)::EncodingEmitter&, mlir::Operation*) + 3148
    frame #5: 0x000000010094d170 test`mlir::writeBytecodeToFile(mlir::Operation*, llvm::raw_ostream&, mlir::BytecodeWriterConfig const&) + 3184
    frame #6: 0x0000000100935ed8 test`mlirOperationWriteBytecode + 208
    frame #7: 0x0000000100170bd8 test`mlir.Operation.writeBytecode__anon_30157(self=<unavailable>, writer=<unavailable>) at mlir.zig:929:37
    frame #8: 0x0000000100169300 test`module.computeModuleHash(platform=platform.Platform @ 0x000000016fdfd7b8, module=mlir.Module @ 0x000000016fdfd858) at module.zig:1072:30
    frame #9: 0x0000000100168f04 test`module.loadOrCompilePjrtExecutable(arena=<unavailable>, platform=platform.Platform @ 0x000000016fdfd7b8, module=mlir.Module @ 0x000000016fdfd858) at module.zig:1122:42
    frame #10: 0x0000000100391f90 test`module.compileInternal__anon_36546(allocator=mem.Allocator @ 0x0000000100cba548, context=0x000000016fdfd7b8, args=meta.MapType(tensor.Tensor,shape.Shape).map(meta.CreateUniqueTuple(1,.{ meta.CreateUniqueTuple(1,.{ tensor.Tensor }) })) @ 0x000000016fdfdf78) at module.zig:924:58
    frame #11: 0x000000010039380c test`module.compileFn__anon_36543(allocator=mem.Allocator @ 0x0000000100cba548, args=meta.MapType(tensor.Tensor,shape.Shape).map(meta.CreateUniqueTuple(1,.{ tensor.Tensor })) @ 0x000000016fdfe838, platform=<unavailable>) at module.zig:1048:43
    frame #12: 0x00000001003939fc test`module.test.unused tensor at module.zig:1604:30
    frame #13: 0x0000000100003728 test`test_runner.asyncMain at test_runner.zig:67:25
    frame #14: 0x0000000100005fa4 test`threaded.AsyncThread.main__anon_16760(allocator_=<unavailable>) at threaded.zig:91:28
    frame #15: 0x0000000100002e4c test`test_runner.main at test_runner.zig:24:31
    frame #16: 0x0000000100002c88 test`start.main [inlined] start.callMain at start.zig:532:37
    frame #17: 0x0000000100002c80 test`start.main at start.zig:492:20
    frame #18: 0x0000000100002c20 test`start.main(c_argc=1, c_argv=0x000000016fdff428, c_envp=0x000000016fdff438) at start.zig:507:75
    frame #19: 0x0000000195eaf154 dyld`start + 2476
``` test "unused tensor" { const zml = @import("zml.zig"); const platform = zml.testing.env(); const Local = struct { pub fn forward(x: Tensor) Tensor { const y = x.addConstant(1); _ = y; return x; } }; const mod = try compileFn(std.testing.allocator, Local.forward, .{ Shape.init(.{ 10 }, .f32) }, platform); defer mod.deinit(); } ``` error: ``` * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0) * frame #0: 0x0000000100952fb0 test`(anonymous namespace)::BytecodeWriter::writeUseListOrders((anonymous namespace)::EncodingEmitter&, unsigned char&, mlir::ValueRange) + 548 frame #1: 0x0000000100956b54 test`(anonymous namespace)::BytecodeWriter::writeRegions((anonymous namespace)::EncodingEmitter&, llvm::MutableArrayRef<mlir::Region>)::'lambda'(mlir::Region&)::operator()(mlir::Region&) const + 1636 frame #2: 0x00000001009529f8 test`(anonymous namespace)::BytecodeWriter::writeOp((anonymous namespace)::EncodingEmitter&, mlir::Operation*) + 3148 frame #3: 0x0000000100956ba0 test`(anonymous namespace)::BytecodeWriter::writeRegions((anonymous namespace)::EncodingEmitter&, llvm::MutableArrayRef<mlir::Region>)::'lambda'(mlir::Region&)::operator()(mlir::Region&) const + 1712 frame #4: 0x00000001009529f8 test`(anonymous namespace)::BytecodeWriter::writeOp((anonymous namespace)::EncodingEmitter&, mlir::Operation*) + 3148 frame #5: 0x000000010094d170 test`mlir::writeBytecodeToFile(mlir::Operation*, llvm::raw_ostream&, mlir::BytecodeWriterConfig const&) + 3184 frame #6: 0x0000000100935ed8 test`mlirOperationWriteBytecode + 208 frame #7: 0x0000000100170bd8 test`mlir.Operation.writeBytecode__anon_30157(self=<unavailable>, writer=<unavailable>) at mlir.zig:929:37 frame #8: 0x0000000100169300 test`module.computeModuleHash(platform=platform.Platform @ 0x000000016fdfd7b8, module=mlir.Module @ 0x000000016fdfd858) at module.zig:1072:30 frame #9: 0x0000000100168f04 test`module.loadOrCompilePjrtExecutable(arena=<unavailable>, platform=platform.Platform @ 0x000000016fdfd7b8, module=mlir.Module @ 0x000000016fdfd858) at module.zig:1122:42 frame #10: 0x0000000100391f90 test`module.compileInternal__anon_36546(allocator=mem.Allocator @ 0x0000000100cba548, context=0x000000016fdfd7b8, args=meta.MapType(tensor.Tensor,shape.Shape).map(meta.CreateUniqueTuple(1,.{ meta.CreateUniqueTuple(1,.{ tensor.Tensor }) })) @ 0x000000016fdfdf78) at module.zig:924:58 frame #11: 0x000000010039380c test`module.compileFn__anon_36543(allocator=mem.Allocator @ 0x0000000100cba548, args=meta.MapType(tensor.Tensor,shape.Shape).map(meta.CreateUniqueTuple(1,.{ tensor.Tensor })) @ 0x000000016fdfe838, platform=<unavailable>) at module.zig:1048:43 frame #12: 0x00000001003939fc test`module.test.unused tensor at module.zig:1604:30 frame #13: 0x0000000100003728 test`test_runner.asyncMain at test_runner.zig:67:25 frame #14: 0x0000000100005fa4 test`threaded.AsyncThread.main__anon_16760(allocator_=<unavailable>) at threaded.zig:91:28 frame #15: 0x0000000100002e4c test`test_runner.main at test_runner.zig:24:31 frame #16: 0x0000000100002c88 test`start.main [inlined] start.callMain at start.zig:532:37 frame #17: 0x0000000100002c80 test`start.main at start.zig:492:20 frame #18: 0x0000000100002c20 test`start.main(c_argc=1, c_argv=0x000000016fdff428, c_envp=0x000000016fdff438) at start.zig:507:75 frame #19: 0x0000000195eaf154 dyld`start + 2476 ```
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DKB/zml#97
No description provided.