| // An example of setting up the embedded-sync driver. | |
| #include <stddef.h> | |
| #include "iree/hal/local/executable_loader.h" | |
| #include "iree/hal/local/loaders/embedded_library_loader.h" | |
| #include "iree/hal/local/sync_device.h" | |
| #include "samples/device/device.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_hal_executable_loader_t* loader = NULL; | |
| IREE_RETURN_IF_ERROR(iree_hal_embedded_library_loader_create( | |
| iree_hal_executable_import_provider_null(), host_allocator, &loader)); | |
| // Use the default host allocator for buffer allocations. | |
| iree_string_view_t identifier = iree_make_cstring_view("dylib"); | |
| iree_hal_allocator_t* device_allocator = NULL; | |
| iree_status_t status = iree_hal_allocator_create_heap( | |
| identifier, host_allocator, host_allocator, &device_allocator); | |
| // Create the synchronous device and release the loader afterwards. | |
| if (iree_status_is_ok(status)) { | |
| 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; | |
| } |