blob: 424144ecb5bcf0320e0f96c3371c113abcafd4bb [file] [log] [blame]
Geoffrey Martin-Noble552d3f82021-05-25 17:56:09 -07001// Copyright 2021 The IREE Authors
CindyLiue040f812021-05-03 23:00:48 +00002//
Geoffrey Martin-Noble552d3f82021-05-25 17:56:09 -07003// 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
CindyLiue040f812021-05-03 23:00:48 +00006
7// A example of setting up the the vulkan driver.
8
Ben Vanik931a3b12021-05-20 13:27:13 -07009#include <stddef.h>
10
CindyLiue040f812021-05-03 23:00:48 +000011#include "iree/base/api.h"
12#include "iree/hal/api.h"
Ben Vanik2a240252022-06-06 16:28:33 -070013#include "iree/hal/drivers/vulkan/registration/driver_module.h"
CindyLiue040f812021-05-03 23:00:48 +000014
CindyLiu0c80a862021-06-18 18:50:08 +000015// Compiled module embedded here to avoid file IO:
Scott Toddc4b04e32022-05-23 09:53:20 -070016#include "samples/simple_embedding/simple_embedding_test_bytecode_module_vulkan_c.h"
CindyLiu0c80a862021-06-18 18:50:08 +000017
Ben Vanik0dd0cfc2021-11-29 16:32:50 -080018iree_status_t create_sample_device(iree_allocator_t host_allocator,
19 iree_hal_device_t** out_device) {
20 // Only register the Vulkan HAL driver.
CindyLiue040f812021-05-03 23:00:48 +000021 IREE_RETURN_IF_ERROR(iree_hal_vulkan_driver_module_register(
22 iree_hal_driver_registry_default()));
Ben Vanik0dd0cfc2021-11-29 16:32:50 -080023
24 // Create the HAL driver from the name.
CindyLiue040f812021-05-03 23:00:48 +000025 iree_hal_driver_t* driver = NULL;
26 iree_string_view_t identifier = iree_make_cstring_view("vulkan");
Ben Vanik1c84fdf2022-06-08 12:03:16 -070027 iree_status_t status = iree_hal_driver_registry_try_create(
Ben Vanik0dd0cfc2021-11-29 16:32:50 -080028 iree_hal_driver_registry_default(), identifier, host_allocator, &driver);
29
30 // Create the default device (primary GPU).
31 if (iree_status_is_ok(status)) {
32 status = iree_hal_driver_create_default_device(driver, host_allocator,
33 out_device);
34 }
35
CindyLiue040f812021-05-03 23:00:48 +000036 iree_hal_driver_release(driver);
37 return iree_ok_status();
38}
CindyLiu0c80a862021-06-18 18:50:08 +000039
40const iree_const_byte_span_t load_bytecode_module_data() {
41 const struct iree_file_toc_t* module_file_toc =
42 iree_samples_simple_embedding_test_module_vulkan_create();
43 return iree_make_const_byte_span(module_file_toc->data,
44 module_file_toc->size);
45}