iree/samples/static_library/static_library_demo.c
iree_status_t create_device_with_static_loader(iree_allocator_t host_allocator,
                                               iree_hal_device_t** out_device) {
  iree_status_t status = iree_ok_status();

  // Set paramters for the device created in the next step.
  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 =
      simple_mul_dispatch_0_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;
  if (iree_status_is_ok(status)) {
    status = iree_hal_static_library_loader_create(
        IREE_ARRAYSIZE(libraries), libraries,
        iree_hal_executable_import_provider_null(), host_allocator,
        &library_loader);
  }

  // Use the default host allocator for buffer allocations.
  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);
  }

  // Create the device and release the executor and loader afterwards.
  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;
}
// A function to create the HAL device from the different backend targets.
// The HAL device is returned based on the implementation, and it must be
// released by the caller.
A function to create the HAL device from the different backend targets.
The HAL device is returned based on the implementation, and it must be
released by the caller.
A function to create the HAL device from the different backend targets . The HAL device is returned based on the implementation and it must be released by the caller .
iree_status_t create_device_with_static_loader(iree_allocator_t host_allocator,
                                               iree_hal_device_t** out_device) {
  iree_status_t status = iree_ok_status();
  iree_hal_sync_device_params_t params;
  iree_hal_sync_device_params_initialize(&params);
  const iree_hal_executable_library_header_t** static_library =
      simple_mul_dispatch_0_library_query(
          IREE_HAL_EXECUTABLE_LIBRARY_LATEST_VERSION, NULL);
  const iree_hal_executable_library_header_t** libraries[1] = {static_library};
  iree_hal_executable_loader_t* library_loader = NULL;
  if (iree_status_is_ok(status)) {
    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, 1, &library_loader,
        device_allocator, host_allocator, out_device);
  }
  iree_hal_allocator_release(device_allocator);
  iree_hal_executable_loader_release(library_loader);
  return status;
}
iree_status_t create_device_with_static_loader ( iree_allocator_t host_allocator , iree_hal_device_t * * out_device ) { iree_status_t status = iree_ok_status ( ) ; iree_hal_sync_device_params_t params ; iree_hal_sync_device_params_initialize ( & params ) ; const iree_hal_executable_library_header_t * * static_library = simple_mul_dispatch_0_library_query ( IREE_HAL_EXECUTABLE_LIBRARY_LATEST_VERSION , NULL ) ; const iree_hal_executable_library_header_t * * libraries [ 1 ] = { static_library } ; iree_hal_executable_loader_t * library_loader = NULL ; if ( iree_status_is_ok ( status ) ) { 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 ( " " ) ; 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 , 1 , & library_loader , device_allocator , host_allocator , out_device ) ; } iree_hal_allocator_release ( device_allocator ) ; iree_hal_executable_loader_release ( library_loader ) ; return status ; }
A function to create the HAL device from the different backend targets.
A function to create the HAL device from the different backend targets .
// Set paramters for the device created in the next step. // Load the statically embedded library /*reserved=*/ // Use the default host allocator for buffer allocations. // Create the device and release the executor and loader afterwards. /*loader_count=*/