Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 1 | // Copyright 2021 The IREE Authors |
CindyLiu | e040f81 | 2021-05-03 23:00:48 +0000 | [diff] [blame] | 2 | // |
Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 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 |
CindyLiu | e040f81 | 2021-05-03 23:00:48 +0000 | [diff] [blame] | 6 | |
| 7 | // A example of setting up the the vulkan driver. |
| 8 | |
Ben Vanik | 931a3b1 | 2021-05-20 13:27:13 -0700 | [diff] [blame] | 9 | #include <stddef.h> |
| 10 | |
CindyLiu | e040f81 | 2021-05-03 23:00:48 +0000 | [diff] [blame] | 11 | #include "iree/base/api.h" |
| 12 | #include "iree/hal/api.h" |
Ben Vanik | 2a24025 | 2022-06-06 16:28:33 -0700 | [diff] [blame] | 13 | #include "iree/hal/drivers/vulkan/registration/driver_module.h" |
CindyLiu | e040f81 | 2021-05-03 23:00:48 +0000 | [diff] [blame] | 14 | |
CindyLiu | 0c80a86 | 2021-06-18 18:50:08 +0000 | [diff] [blame] | 15 | // Compiled module embedded here to avoid file IO: |
Scott Todd | c4b04e3 | 2022-05-23 09:53:20 -0700 | [diff] [blame] | 16 | #include "samples/simple_embedding/simple_embedding_test_bytecode_module_vulkan_c.h" |
CindyLiu | 0c80a86 | 2021-06-18 18:50:08 +0000 | [diff] [blame] | 17 | |
Ben Vanik | 0dd0cfc | 2021-11-29 16:32:50 -0800 | [diff] [blame] | 18 | iree_status_t create_sample_device(iree_allocator_t host_allocator, |
| 19 | iree_hal_device_t** out_device) { |
| 20 | // Only register the Vulkan HAL driver. |
CindyLiu | e040f81 | 2021-05-03 23:00:48 +0000 | [diff] [blame] | 21 | IREE_RETURN_IF_ERROR(iree_hal_vulkan_driver_module_register( |
| 22 | iree_hal_driver_registry_default())); |
Ben Vanik | 0dd0cfc | 2021-11-29 16:32:50 -0800 | [diff] [blame] | 23 | |
| 24 | // Create the HAL driver from the name. |
CindyLiu | e040f81 | 2021-05-03 23:00:48 +0000 | [diff] [blame] | 25 | iree_hal_driver_t* driver = NULL; |
| 26 | iree_string_view_t identifier = iree_make_cstring_view("vulkan"); |
Ben Vanik | 1c84fdf | 2022-06-08 12:03:16 -0700 | [diff] [blame] | 27 | iree_status_t status = iree_hal_driver_registry_try_create( |
Ben Vanik | 0dd0cfc | 2021-11-29 16:32:50 -0800 | [diff] [blame] | 28 | 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 | |
CindyLiu | e040f81 | 2021-05-03 23:00:48 +0000 | [diff] [blame] | 36 | iree_hal_driver_release(driver); |
| 37 | return iree_ok_status(); |
| 38 | } |
CindyLiu | 0c80a86 | 2021-06-18 18:50:08 +0000 | [diff] [blame] | 39 | |
| 40 | const 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 | } |