Skip to content

Build simple_embedding_run in c API. - #5524

Merged
hcindyl merged 4 commits into
iree-org:mainfrom
hcindyl:simple_embedding_c
Apr 24, 2021
Merged

hcindyl merged 4 commits into
iree-org:mainfrom
hcindyl:simple_embedding_c

Conversation

@hcindyl

@hcindyl hcindyl commented Apr 19, 2021

Copy link
Copy Markdown
Contributor

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.

@hcindyl
hcindyl requested a review from ScottTodd April 19, 2021 21:22
@google-cla google-cla Bot added the cla: yes label Apr 19, 2021
@hcindyl
hcindyl force-pushed the simple_embedding_c branch 3 times, most recently from a56c54f to 572a189 Compare April 19, 2021 23:00
@ScottTodd ScottTodd added the runtime/api IREE's public C runtime API and iree-run-module label Apr 20, 2021
@hcindyl
hcindyl marked this pull request as ready for review April 22, 2021 17:28

@ScottTodd ScottTodd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread iree/samples/simple_embedding/BUILD Resolved
Comment on lines +72 to +82
// 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileToc was renamed to iree_file_toc_t in #5578. Sync with main + apply this fix?

Suggested change
// 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks for fixing the struct type.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +36 to +48
name = "simple_embedding_run",
srcs = ["simple_embedding_run.c"],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's queued up in the next PR. :) I already have the commit ready.

hcindyl added 3 commits April 23, 2021 09:42
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.
@hcindyl
hcindyl force-pushed the simple_embedding_c branch from 3cfa94d to 8b430b2 Compare April 23, 2021 17:35
@hcindyl
hcindyl requested a review from ScottTodd April 23, 2021 18:14
Use create/release instead of initialize/deinitialize per review
feedback.

@benvanik benvanik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm if scott is happy

@ScottTodd

Copy link
Copy Markdown
Member

lgtm if scott is happy

👍 room for follow-up work, but this looks good enough as-is to check in.

@hcindyl

hcindyl commented Apr 24, 2021

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

@hcindyl
hcindyl merged commit b4737c5 into iree-org:main Apr 24, 2021
@hcindyl
hcindyl deleted the simple_embedding_c branch April 26, 2021 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

runtime/api IREE's public C runtime API and iree-run-module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants