blob: f072903b963f2dfbd8f7d497423d0792a1df2536 [file] [log] [blame]
Scott Toddf237b5e2022-01-28 11:02:25 -08001// 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 Vanik325b0442022-06-06 17:14:30 -07007#include "iree/hal/drivers/local_sync/sync_device.h"
Scott Toddf237b5e2022-01-28 11:02:25 -08008#include "iree/hal/local/loaders/static_library_loader.h"
Scott Toddf237b5e2022-01-28 11:02:25 -08009#include "mnist_static.h"
10
11iree_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(&params);
15
Ben Vanik6e015be2022-02-28 22:01:53 -080016 // Register the statically linked executable library.
Scott Toddf6490962022-03-29 10:05:13 -070017 const iree_hal_executable_library_query_fn_t libraries[] = {
Ben Vanik49ffdac2024-10-29 16:24:56 -070018 mnist_linked_library_query,
Ben Vanik6e015be2022-02-28 22:01:53 -080019 };
Scott Toddf237b5e2022-01-28 11:02:25 -080020 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 Todd546d8622024-09-20 10:47:54 -070026 iree_string_view_t identifier = iree_make_cstring_view("local-sync");
Scott Toddf237b5e2022-01-28 11:02:25 -080027 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, &params, /*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}