Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 1 | // Copyright 2022 The IREE Authors |
| 2 | // |
| 3 | // Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | |
Ben Vanik | 325b044 | 2022-06-06 17:14:30 -0700 | [diff] [blame] | 7 | #include "iree/hal/drivers/local_sync/sync_device.h" |
Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 8 | #include "iree/hal/local/loaders/static_library_loader.h" |
Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 9 | #include "mnist_static.h" |
| 10 | |
| 11 | iree_status_t create_device_with_static_loader(iree_allocator_t host_allocator, |
| 12 | iree_hal_device_t** out_device) { |
| 13 | iree_hal_sync_device_params_t params; |
| 14 | iree_hal_sync_device_params_initialize(¶ms); |
| 15 | |
Ben Vanik | 6e015be | 2022-02-28 22:01:53 -0800 | [diff] [blame] | 16 | // Register the statically linked executable library. |
Scott Todd | f649096 | 2022-03-29 10:05:13 -0700 | [diff] [blame] | 17 | const iree_hal_executable_library_query_fn_t libraries[] = { |
Ben Vanik | 49ffdac | 2024-10-29 16:24:56 -0700 | [diff] [blame^] | 18 | mnist_linked_library_query, |
Ben Vanik | 6e015be | 2022-02-28 22:01:53 -0800 | [diff] [blame] | 19 | }; |
Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 20 | iree_hal_executable_loader_t* library_loader = NULL; |
| 21 | iree_status_t status = iree_hal_static_library_loader_create( |
| 22 | IREE_ARRAYSIZE(libraries), libraries, |
| 23 | iree_hal_executable_import_provider_null(), host_allocator, |
| 24 | &library_loader); |
| 25 | |
Scott Todd | 546d862 | 2024-09-20 10:47:54 -0700 | [diff] [blame] | 26 | iree_string_view_t identifier = iree_make_cstring_view("local-sync"); |
Scott Todd | f237b5e | 2022-01-28 11:02:25 -0800 | [diff] [blame] | 27 | iree_hal_allocator_t* device_allocator = NULL; |
| 28 | if (iree_status_is_ok(status)) { |
| 29 | status = iree_hal_allocator_create_heap(identifier, host_allocator, |
| 30 | host_allocator, &device_allocator); |
| 31 | } |
| 32 | |
| 33 | if (iree_status_is_ok(status)) { |
| 34 | status = iree_hal_sync_device_create( |
| 35 | identifier, ¶ms, /*loader_count=*/1, &library_loader, |
| 36 | device_allocator, host_allocator, out_device); |
| 37 | } |
| 38 | |
| 39 | iree_hal_allocator_release(device_allocator); |
| 40 | iree_hal_executable_loader_release(library_loader); |
| 41 | return status; |
| 42 | } |