Repository navigation
Build simple_embedding_run in c API. - #5524
Conversation
a56c54f to
572a189
Compare
572a189 to
30f2a93
Compare
ScottTodd
left a comment
There was a problem hiding this comment.
Looking pretty good, just a few more comments from me.
I'm a little hesitant about the build status of this on Windows, given some slight issues in the c_embed_data implementation on that platform spotted last night, but I'm also fine with fixing forward for those as we don't have many other people building on Windows.
| // Load bytecode module from the embedded data. | ||
| #if IREE_ARCH_RISCV_64 | ||
| const struct FileToc* module_file_toc = | ||
| simple_embedding_test_llvm_aot_rv64_create(); | ||
| #else | ||
| // Note the setup here only supports native build. The bytecode is not built | ||
| // for the cross-compile execution. The code can be compiled but it will | ||
| // hit runtime error in a cross-compile environment. | ||
| const struct FileToc* module_file_toc = | ||
| simple_embedding_test_bytecode_module_c_create(); | ||
| #endif |
There was a problem hiding this comment.
FileToc was renamed to iree_file_toc_t in #5578. Sync with main + apply this fix?
| // Load bytecode module from the embedded data. | |
| #if IREE_ARCH_RISCV_64 | |
| const struct FileToc* module_file_toc = | |
| simple_embedding_test_llvm_aot_rv64_create(); | |
| #else | |
| // Note the setup here only supports native build. The bytecode is not built | |
| // for the cross-compile execution. The code can be compiled but it will | |
| // hit runtime error in a cross-compile environment. | |
| const struct FileToc* module_file_toc = | |
| simple_embedding_test_bytecode_module_c_create(); | |
| #endif | |
| // Load bytecode module from the embedded data. | |
| #if IREE_ARCH_RISCV_64 | |
| const struct iree_file_toc_t* module_file_toc = | |
| simple_embedding_test_llvm_aot_rv64_create(); | |
| #else | |
| // Note the setup here only supports native build. The bytecode is not built | |
| // for the cross-compile execution. The code can be compiled but it will | |
| // hit runtime error in a cross-compile environment. | |
| const struct iree_file_toc_t* module_file_toc = | |
| simple_embedding_test_bytecode_module_c_create(); | |
| #endif |
There was a problem hiding this comment.
Done. Thanks for fixing the struct type.
There was a problem hiding this comment.
I do a similar thing to this here:
https://github.com/google/iree/blob/a8d76f0679e3d7fc6e7429355a53fcd55395deb7/iree/hal/local/elf/elf_module_test.cc#L32-L61
which is easier to scale out to new architectures (though still not great). I was going to add an IREE_ARCH_NAME define that would expand to one of these suffixes and then there's no need for any #ifdefs - just "my_base_name_" IREE_ARCH_NAME ".vmfb"
the real goal here is to get multi-architecture IREE modules so none of this is needed - that's next on my plate
There was a problem hiding this comment.
Understood. The challenge/difference in this example is that the default .vmfb is built from the iree_bytecode_module rule, so it does not have the arch_name suffix. I can change the "riscv_64" suffix for the riscv64 case, but it doesn't matter that much if we can't change the default.
Besides. In order to support the simple_embedding_test coverage, the default simple_embedding_bytecode_module.vmfb is built with both dylib and vulkan HAL, whereas for riscv we only going to test/support dylib. I want to distinguish that from the name too.
Agree supporting multi-architecture build will be better, however, it would only address the LLVM AOT path, however, not sure how/if it can be integrated with the Vulkan path.
There was a problem hiding this comment.
We'll be able to have all targets compiled in - and for a sample we'd do that - so a single vmfb for all CPU architectures and vulkan/cuda/etc - that just works with none of this #ifdef trickery. If we wanted something that only compiled in a single variant then we'd want to inject that instead of pulling it like we do here (or in the elf_module_test): the sample would just calls an extern C function (load_sample_module() etc) that then is controlled by the build system based on what you link in, which could just be whatever your CMake target is.
This is fine for now, though.
| name = "simple_embedding_run", | ||
| srcs = ["simple_embedding_run.c"], |
There was a problem hiding this comment.
For #5481, I'll want to delete simple_embedding_test if this simple_embedding_run demonstrates enough of the same things. We can leave that for follow-up work.
There was a problem hiding this comment.
It's queued up in the next PR. :) I already have the commit ready.
The simple_embedding_run target has a IREE::Samples::simple_embedding::Run function that executes the bytecode of simle_embedding_test.mlir with c APIs. The function supports all available HAL drivers, and is selectable in the function argument, e.g., > simple_embedding_run dylib The function also supports cross-compilation, if the cross-compiled bytecode module is available. The function can be used to replace the core function of simple_embeding_test in a following patch.
Use iree_file_toc_t instead.
3cfa94d to
8b430b2
Compare
Use create/release instead of initialize/deinitialize per review feedback.
benvanik
left a comment
There was a problem hiding this comment.
lgtm if scott is happy
👍 room for follow-up work, but this looks good enough as-is to check in. |
|
Thanks for the review! |
The simple_embedding_run target has a
IREE::Samples::simple_embedding::Run function that executes
the bytecode of simle_embedding_test.mlir with c APIs.
The function supports all available HAL drivers, and is
selectable in the function argument, e.g.,
The function also supports cross-compilation, if the cross-compiled
bytecode module is available.
The function can be used to replace the core function of
simple_embeding_test in a following patch.