TensorFlow lite cmake compilation failed to allocate memory
Hi @lorenzodellagiustina, my current best guess is you are suffering from too much virtualization and the memory isn't being allocated across the virtual layers as well as you think it is. Is there any way to remove one of the layers, if only temporarily to figure out where the root of this problem lies? Otherwise can you check how much memory is actually allocated to WSL 2 and then how much memory is actually accessible to the docker? > Hi @lorenzodellagiustina, my current best guess is you are suffering from too much virtualization and the memory isn't being allocated across the virtual layers as well as you think it is. Is there any way to remove one of the layers, if only temporarily to figure out where the root of this problem lies? Otherwise can you check how much memory is actually allocated to WSL 2 and then how much memory is actually accessible to the docker?

@Luca-Stefanescu

Thanks for your quick response. Turned out to be a problem with the `-j` flag of the command `cmake --build`. This flags is used to specify the number of parallel build jobs to run simultaneously. It should be used followed by a number (the number of cpu cores of my machine worked fine for me). I guess that if a number is not specified the build will be parallelized as much as possible trying to allocate way too memory (even github actions failed to build the "minimal" example).
I think that this should be written in the guide for building TFLite with CMake. Just adding a note about the usage of `-j` flag would have saved me a lot of hours. Maybe I'll just open a pull request and I'll link it to this issue in the next days.

Thanks for your help. @lorenzodellagiustina np, Thanks for letting us know, can you please close this issue as completed if you have no more open items? Thanks! Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/61921">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/61921">No</a>

Any update with this issue? I'm having the same problem described by @Luca-Stefanescu

I am building Tensorflow Lite with cmake following the instruction given on the minimal example. I am building in a docker container with ubuntu using WSL 2 with docker desktop. The build seems to work until 91%. Then it will start to allocate all the memory (16gb of ram + 8gb of swap) until it fails to allocate throwing an allocation error or sometimes an input/output error.
I think that this error message could be helpful:
```
In file included from /workspaces/tfl-dev-env/tie/../tensorflow_src/tensorflow/lite/kernels/internal/runtime_shape.h:22,
                 from /workspaces/tfl-dev-env/tie/../tensorflow_src/tensorflow/lite/kernels/internal/types.h:24,
                 from /workspaces/tfl-dev-env/tie/../tensorflow_src/tensorflow/lite/kernels/internal/tensor_ctypes.h:22,
                 from /workspaces/tfl-dev-env/tensorflow_src/tensorflow/lite/kernels/embedding_lookup_sparse.cc:72:
/usr/include/c++/13/memory:81:12: fatal error: /workspaces/tfl-dev-env/tie/../tensorflow_src/bits/shared_ptr_atomic.h: Cannot allocate memory
   81 | #  include <bits/shared_ptr_atomic.h>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
```

However trying to follow the same steps on a ubuntu VM using VMWare (and with less memory) seems to work.

_Originally posted by @lorenzodellagiustina in https://github.com/tensorflow/tensorflow/issues/61485#issuecomment-1725196272_
            