Rework includes and directory names for samples. (#9177)
Refactoring after https://github.com/google/iree/pull/8958 shuffled these files around, aiming to remove custom logic in samples that we want users to be able to fork easily.
Paths are reverted from `iree_[sample_name]` back to `[sample_name]`
Includes changed to match:
| | |
| -- | -- |
| C++ includes before | `#include "iree_[sample_name]/[header_name].h"` |
| C++ includes now | `#include "samples/[sample_name]/[header_name].h"` |
| Another option | `#include "header_name.h"`
The third option would require adding
```
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
```
to `target_include_directories()` (I already do that in the experimental web samples)diff --git a/samples/simple_embedding/device_vmvx_sync.c b/samples/simple_embedding/device_vmvx_sync.c
new file mode 100644
index 0000000..0683405
--- /dev/null
+++ b/samples/simple_embedding/device_vmvx_sync.c
@@ -0,0 +1,59 @@
+// Copyright 2021 The IREE Authors
+//
+// Licensed under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// A example of setting up the vmvx-sync driver.
+
+#include <stddef.h>
+
+#include "iree/base/api.h"
+#include "iree/hal/api.h"
+#include "iree/hal/local/executable_loader.h"
+#include "iree/hal/local/loaders/vmvx_module_loader.h"
+#include "iree/hal/local/sync_device.h"
+
+// Compiled module embedded here to avoid file IO:
+#include "samples/simple_embedding/simple_embedding_test_bytecode_module_vmvx_c.h"
+
+iree_status_t create_sample_device(iree_allocator_t host_allocator,
+ iree_hal_device_t** out_device) {
+ // Set parameters for the device created in the next step.
+ iree_hal_sync_device_params_t params;
+ iree_hal_sync_device_params_initialize(¶ms);
+
+ iree_vm_instance_t* instance = NULL;
+ IREE_RETURN_IF_ERROR(iree_vm_instance_create(host_allocator, &instance));
+
+ iree_hal_executable_loader_t* loader = NULL;
+ iree_status_t status =
+ iree_hal_vmvx_module_loader_create(instance, host_allocator, &loader);
+ iree_vm_instance_release(instance);
+
+ // Use the default host allocator for buffer allocations.
+ iree_string_view_t identifier = iree_make_cstring_view("vmvx");
+ iree_hal_allocator_t* device_allocator = NULL;
+ if (iree_status_is_ok(status)) {
+ status = iree_hal_allocator_create_heap(identifier, host_allocator,
+ host_allocator, &device_allocator);
+ }
+
+ if (iree_status_is_ok(status)) {
+ // Create the synchronous device.
+ status = iree_hal_sync_device_create(
+ identifier, ¶ms, /*loader_count=*/1, &loader, device_allocator,
+ host_allocator, out_device);
+ }
+
+ iree_hal_allocator_release(device_allocator);
+ iree_hal_executable_loader_release(loader);
+ return status;
+}
+
+const iree_const_byte_span_t load_bytecode_module_data() {
+ const struct iree_file_toc_t* module_file_toc =
+ iree_samples_simple_embedding_test_module_vmvx_create();
+ return iree_make_const_byte_span(module_file_toc->data,
+ module_file_toc->size);
+}