m4rs-mt / ILGPU

ILGPU JIT Compiler for high-performance .Net GPU programs
http://www.ilgpu.net
Other
1.34k stars 115 forks source link

[BUG]: `IRContext.Import(Method)` does not correctly duplicate the full IR graph #1222

Closed IsaMorphic closed 3 months ago

IsaMorphic commented 3 months ago

Describe the bug

When calling IRContext.Import(Method), it is evident (through ongoing investigation) that there are some parts of the IR graph that remain untraversed, even though IRRebuilder.CloneMode is being used for this purpose.

Environment

Steps to reproduce

  1. Check-out ir-importer on my fork of this project
  2. Run unit tests
  3. Observe that all of them fail due to KeyNotFoundException, indicating that IRContext.Import(Method) did not perform a complete traversal of the input Method instance and all of its dependencies (i.e. some dependencies are missing altogether).

Expected behavior

I should be able to run the unit tests without observing this failure.

Additional context

On this fork of ILGPU, I am developing an IR export/import pipeline that can persist an in-memory IRContext for future recall / use at runtime. This is for the NativeAOT support feature.

IsaMorphic commented 3 months ago

From some dynamic analysis, it appears that IRRebuilder.CloneMode "forgets" to clone Parameter values for each Method. Just a hunch, though.

IsaMorphic commented 3 months ago

I ended up finding that this was a bug on the consumer side of the API, related to read-locking of the IRContext. Consider this a misreport!