$ sh build.sh
...
...
Will take a while if you don't have a fast internet, unless we manage to make a tarball with all iree submodules bundled
...
...
...
$ ./build/iree-standalone-sample
Available driver: local-sync (Local execution using a lightweight inline synchronous queue)
Available driver: local-task (Local execution using the IREE multithreading task system)
Last active
January 22, 2023 18:00
-
-
Save bsergean/8b68218e08bd97e1027eece129ca6c9d to your computer and use it in GitHub Desktop.
Building an iree simple runtime program, using cmake fetchcontent to download iree.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake -GNinja -Bbuild . | |
cmake --build build | |
# ./build/iree-standalone-sample |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copy pasted with few changes (see at the bottom) on January the 23th, 2023 | |
# From https://github.com/iree-org/iree-samples/blob/main/cpp/CMakeLists.txt | |
# | |
# 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 | |
cmake_minimum_required(VERSION 3.21...3.23) | |
#------------------------------------------------------------------------------- | |
# Project configuration | |
#------------------------------------------------------------------------------- | |
project(iree-samples C CXX) | |
set(CMAKE_C_STANDARD 11) | |
set(CMAKE_CXX_STANDARD 17) | |
set_property(GLOBAL PROPERTY USE_FOLDERS ON) | |
#------------------------------------------------------------------------------- | |
# Core project dependency | |
#------------------------------------------------------------------------------- | |
message(STATUS "Fetching core IREE repo (this may take a few minutes)...") | |
# Note: for log output, set -DFETCHCONTENT_QUIET=OFF, | |
# see https://gitlab.kitware.com/cmake/cmake/-/issues/18238#note_440475 | |
include(FetchContent) | |
FetchContent_Declare( | |
iree | |
GIT_REPOSITORY https://github.com/iree-org/iree.git | |
GIT_TAG 7a435f0e45b2dbc3988c1a751e6810cd80c2dd83 # 2022-09-12 | |
GIT_SUBMODULES_RECURSE OFF | |
GIT_SHALLOW OFF | |
GIT_PROGRESS ON | |
USES_TERMINAL_DOWNLOAD ON | |
) | |
# Extend module path to find MLIR CMake modules. | |
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/mlir") | |
# Disable core project features not needed for these out of tree samples. | |
set(IREE_BUILD_TESTS OFF CACHE BOOL "" FORCE) | |
set(IREE_BUILD_SAMPLES OFF CACHE BOOL "" FORCE) | |
set(IREE_BUILD_COMPILER OFF CACHE BOOL "" FORCE) | |
set(IREE_BUILD_BINDINGS_TFLITE OFF CACHE BOOL "" FORCE) | |
set(IREE_BUILD_BINDINGS_TFLITE_JAVA OFF CACHE BOOL "" FORCE) | |
# "IREE_BUILD_COMPILER OFF" | |
# "IREE_BUILD_TESTS OFF" | |
# "IREE_BUILD_SAMPLES OFF" | |
# "IREE_BUILD_BINDINGS_TFLITE OFF" | |
# "IREE_BUILD_BINDINGS_TFLITE_JAVA OFF" | |
FetchContent_MakeAvailable(iree) | |
FetchContent_GetProperties(iree SOURCE_DIR IREE_SOURCE_DIR) | |
#------------------------------------------------------------------------------- | |
# Individual samples | |
#------------------------------------------------------------------------------- | |
# | |
# FIXME start modifications | |
# | |
# add_subdirectory(vision_inference) | |
# add_subdirectory(vulkan_gui) | |
set(_NAME "iree-standalone-sample") | |
add_executable(${_NAME} "") | |
target_sources(${_NAME} | |
PRIVATE | |
"iree-standalone-sample.c" | |
) | |
target_link_libraries(${_NAME} | |
iree_base_base | |
iree_base_tracing | |
iree_hal_hal | |
iree_runtime_runtime | |
) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copy pasted with no changes on January the 23th, 2023 | |
// From https://github.com/iree-org/iree-samples/blob/main/runtime-library/test_api.c | |
// | |
// Copyright 2023 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 | |
// Simple test program that uses the HAL API to list available drivers. | |
// This is just to ensure that it is possible to use the library. | |
#include <iree/hal/api.h> | |
#include <iree/hal/drivers/init.h> | |
#include <stdio.h> | |
int main(int argc, char **argv) { | |
iree_hal_driver_registry_t *registry = iree_hal_driver_registry_default(); | |
IREE_CHECK_OK(iree_hal_register_all_available_drivers(registry)); | |
iree_host_size_t driver_count; | |
iree_hal_driver_info_t *driver_infos; | |
IREE_CHECK_OK(iree_hal_driver_registry_enumerate( | |
registry, iree_allocator_system(), &driver_count, &driver_infos)); | |
for (iree_host_size_t i = 0; i < driver_count; ++i) { | |
printf("Available driver: %.*s (%.*s)\n", | |
(int)driver_infos[i].driver_name.size, | |
driver_infos[i].driver_name.data, | |
(int)driver_infos[i].full_name.size, driver_infos[i].full_name.data); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment