modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo
Other
22.25k stars 2.55k forks source link

[BUG]: elf_dynamic_array_reader.h:64] tag not found #1868

Open friedrixk opened 4 months ago

friedrixk commented 4 months ago

Bug description

This may be related to Issues #1042, #1601, #1738, #1776 but the seemingly random occurrence is weird and there are no tensors involved in my code.

I am experiencing seemingly random elf_dynamic_array_reader.h:64] tag not found and scaling_cur_freq and scaling_max_freq, No such file or directory-errors when executing max_cut.mojo since updating to Mojo v24.1.0:

vscode ➜ /workspaces/ubuntu (1-refactoring) $ mojo max_cut.mojo
[7650:7650:20240303,130823.040133:ERROR elf_dynamic_array_reader.h:64] tag not found
[7650:7650:20240303,130823.040251:ERROR elf_dynamic_array_reader.h:64] tag not found
[7650:7650:20240303,130823.040316:ERROR elf_dynamic_array_reader.h:64] tag not found
[7650:7650:20240303,130823.040405:ERROR elf_dynamic_array_reader.h:64] tag not found
[7650:7650:20240303,130823.040493:ERROR elf_dynamic_array_reader.h:64] tag not found
[7650:7650:20240303,130823.040525:ERROR elf_dynamic_array_reader.h:64] tag not found
[7650:7650:20240303,130823.043415:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[7650:7650:20240303,130823.043463:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0.      Program arguments: mojo max_cut.mojo
 #0 0x0000557bfce01e47 (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x62ae47)
 #1 0x0000557bfcdffa1e (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x628a1e)
 #2 0x0000557bfce0251f (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x62b51f)
 #3 0x00007f4df039c520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000557bff1057a6 (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x292e7a6)
 #5 0x0000557bff10570e (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x292e70e)
 #6 0x0000557bff105651 (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x292e651)
 #7 0x0000557bff110a4a (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x2939a4a)
 #8 0x0000557bff868538 (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x3091538)
 #9 0x00007f4de681a1b5 KGEN_CompilerRT_AlignedAlloc (/home/vscode/.modular/pkg/packages.modular.com_mojo/lib/libKGENCompilerRTShared.so.19git+0x251b5)
#10 0x00007f4d78002017 
Segmentation fault

Steps to reproduce

You can reproduce the errors by executing max_cut.mojo

This is max_cut.mojo:

from python import Python
from sys import argv
from graph import Graph

fn test_graph_ds() raises:
    var g = Graph()
    g.add_vertex(1)

    var n = g.get_neighbors(1)
    var es = g.get_edges()

fn main() raises:

    # Import local python modules
    Python.add_to_path("./ilp")
    var ilp = Python.import_module("ilp")

    # test graph data structure
    test_graph_ds()
    test_graph_ds()

    # run approximation algorithm

This is graph.mojo:

from collections.vector import DynamicVector
from collections import Dict, KeyElement

@value
struct IntKey(KeyElement):
    var i: Int

    fn __init__(inout self, owned i: Int):
        self.i = i

    fn __hash__(self) -> Int:
        return hash(self.i)

    fn __eq__(self, other: Self) -> Bool:
        return self.i == other.i

struct Graph:
    var vertices: DynamicVector[Int]
    var edges: Dict[IntKey, DynamicVector[Int]]

    fn __init__(inout self):
        self.vertices = DynamicVector[Int]()
        self.edges = Dict[IntKey, DynamicVector[Int]]()

    fn add_vertex(inout self, v: Int):
        if IntKey(v) in self.edges:
            print("Vertex " + str(v) + " already exists")
        else:
            self.vertices.push_back(v)
            self.edges.__setitem__(IntKey(v), DynamicVector[Int]())

    fn add_edge(inout self, v:Int, u:Int) raises:
        if not self.contains_edge(v, u):    
            if IntKey(v) not in self.edges:
                self.edges.__setitem__(IntKey(v), DynamicVector[Int]())
            if IntKey(u) not in self.edges:
                self.edges.__setitem__(IntKey(u), DynamicVector[Int]())
            self.edges[IntKey(v)].push_back(u)  # directed
            self.edges[IntKey(u)].push_back(v)  # undirected
        else:
            print("Edge " + str(v) + "->" + str(u) + " already exists")

    fn contains_edge(self, v: Int, u: Int) raises -> Bool:
        if IntKey(v) in self.edges:
            var neighbors = self.edges[IntKey(v)]
            for i in range(len(neighbors)):
                var neighbor = neighbors[i]
                if neighbor == u:
                    return True
        return False

    fn get_vertices(self) -> DynamicVector[Int]:
        return self.vertices

    fn get_edges(inout self) -> Dict[IntKey, DynamicVector[Int]]:
        return self.edges

    fn get_neighbors(self, v: Int) raises -> DynamicVector[Int]:
        return self.edges[IntKey(v)]

    fn delete_vertex(inout self, v: Int) raises:
        for i in range(len(self.vertices)):
            if self.contains_edge(v, self.vertices[i]):
                self.delete_edge(v, self.vertices[i])
        var value = self.edges.pop(IntKey(v))

    fn delete_edge(inout self, v: Int, u: Int) raises:
        self.delete_directed_edge(v, u)
        self.delete_directed_edge(u, v)

    fn delete_directed_edge(inout self, v: Int, u: Int) raises:
        if self.contains_edge(v, u):
            var new_neighbors = DynamicVector[Int]()
            var neighbors = self.edges[IntKey(v)]
            for i in range(len(neighbors)):
                if neighbors[i] != u:
                    new_neighbors.push_back(neighbors[i])
            self.edges[IntKey(v)] = new_neighbors
        else:
            print("Edge " + str(v) + "->" + str(u) + " does not exist")

    fn print_vertices(self):
        for i in range(len(self.vertices)):
            print(self.vertices[i])

    fn print_edges(self) raises:
        for i in range(len(self.vertices)):
            var v = self.vertices[i]
            var neighbors = self.edges[IntKey(v)]
            for j in range(len(neighbors)):
                var u = neighbors[j]
                print(str(v) + "->" + str(u))

    fn __copyinit__(inout self, other: Self):
        self.vertices = other.vertices
        self.edges = other.edges

Note:

There is at least four ways to get rid of the errors through commenting out code snippets in max_cut.mojo:

  1. Comment out line 9: var n = g.get_neighbors(1)
  2. Comment out line 10: var es = g.get_edges()
  3. Comment out lines 16 and 17: Python.add_to_path("./ilp") and var ilp = Python.import_module("ilp")
  4. Comment out line 21: test_graph_ds()

When solely commenting out line 17 (var ilp = Python.import_module("ilp")) the elf_dynamic_array_reader.h:64] tag not found- errors disappear but the file_io_posix-errors remain:

vscode ➜ /workspaces/ubuntu (1-refactoring) $ mojo max_cut.mojo
[12577:12577:20240303,133559.804055:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[12577:12577:20240303,133559.804147:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0.      Program arguments: mojo max_cut.mojo
 #0 0x00005635fefe3e47 (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x62ae47)
 #1 0x00005635fefe1a1e (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x628a1e)
 #2 0x00005635fefe451f (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x62b51f)
 #3 0x00007ff3afb35520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00005636012e77a6 (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x292e7a6)
 #5 0x00005636012e770e (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x292e70e)
 #6 0x00005636012e7651 (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x292e651)
 #7 0x00005636012f2a4a (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x2939a4a)
 #8 0x0000563601a4a538 (/home/vscode/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x3091538)
 #9 0x00007ff3aa1eb1b5 KGEN_CompilerRT_AlignedAlloc (/home/vscode/.modular/pkg/packages.modular.com_mojo/lib/libKGENCompilerRTShared.so.19git+0x251b5)
#10 0x00007ff334002017 
Segmentation fault

System information

I am using

- VSCode Dev Container with Ubuntu 22.04.3 LTS

- mojo 24.1.0 (55ec12d6)

- modular 0.5.1 (1b608e3d)
friedrixk commented 4 months ago

May be duplicate of / related to #1601, #1738 and #1776

friedrixk commented 4 months ago

The problem may be related to the dIct that is returned in graph.get_edges(). I replaced

fn get_edges(inout self) raises -> Dict[Int, DynamicVector[Int]]:
        return self.edges

with this:

  fn get_edges(self) raises -> DynamicVector[DynamicVector[Int]]:
      var es = DynamicVector[DynamicVector[Int]]()
      for i in range(len(self.vertices)):
          var v = self.vertices[i]
          var neighbors = self.edges[v]
          for j in range(len(neighbors)):
              var u = neighbors[j]
              var e = DynamicVector[Int]()
              e.push_back(v)
              e.push_back(u)
              es.push_back(e)
      return es

i.e., get_edges() returns a DynamicVector[DynamicVector[Int]] instead of the dict. Like this, there is no error whatsoever anymore. But I would like to return the dict of course.