blob: 82e291d585a8bbf8ac83e5322a84d091eb94a774 [file] [log] [blame]
// Copyright 2022 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
#include "iree/hal/local/loaders/static_library_loader.h"
#include "iree/hal/local/sync_device.h"
#include "mnist_static.h"
iree_status_t create_device_with_static_loader(iree_allocator_t host_allocator,
iree_hal_device_t** out_device) {
iree_hal_sync_device_params_t params;
iree_hal_sync_device_params_initialize(&params);
// Load the statically embedded library.
const iree_hal_executable_library_header_t** static_library =
mnist_linked_llvm_library_query(
IREE_HAL_EXECUTABLE_LIBRARY_LATEST_VERSION,
/*reserved=*/NULL);
const iree_hal_executable_library_header_t** libraries[1] = {static_library};
iree_hal_executable_loader_t* library_loader = NULL;
iree_status_t status = iree_hal_static_library_loader_create(
IREE_ARRAYSIZE(libraries), libraries,
iree_hal_executable_import_provider_null(), host_allocator,
&library_loader);
iree_string_view_t identifier = iree_make_cstring_view("sync");
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)) {
status = iree_hal_sync_device_create(
identifier, &params, /*loader_count=*/1, &library_loader,
device_allocator, host_allocator, out_device);
}
iree_hal_allocator_release(device_allocator);
iree_hal_executable_loader_release(library_loader);
return status;
}