Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
makslevental committed Oct 16, 2024
1 parent 6590d17 commit 72e2c27
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 147 deletions.
38 changes: 16 additions & 22 deletions runtime/src/iree-amd-aie/driver/xrt-lite/allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ struct iree_hal_xrt_lite_allocator {
}
};

iree_hal_buffer_compatibility_t query_buffer_compatibility(
iree_hal_buffer_compatibility_t
iree_hal_xrt_lite_allocator_query_buffer_compatibility(
iree_hal_allocator_t* base_allocator, iree_hal_buffer_params_t* params,
iree_device_size_t* allocation_size) {
// All buffers can be allocated on the heap.
iree_hal_buffer_compatibility_t compatibility =
IREE_HAL_BUFFER_COMPATIBILITY_ALLOCATABLE;

Expand All @@ -50,7 +50,6 @@ iree_hal_buffer_compatibility_t query_buffer_compatibility(
}
}

// We are now optimal.
params->type &= ~IREE_HAL_MEMORY_TYPE_OPTIMAL;

// Guard against the corner case where the requested buffer size is 0. The
Expand All @@ -65,16 +64,16 @@ iree_hal_buffer_compatibility_t query_buffer_compatibility(
return compatibility;
}

iree_status_t allocate_buffer(iree_hal_allocator_t* base_allocator,
const iree_hal_buffer_params_t* params,
iree_device_size_t allocation_size,
iree_hal_buffer_t** out_buffer) {
iree_status_t iree_hal_xrt_lite_allocator_allocate_buffer(
iree_hal_allocator_t* base_allocator,
const iree_hal_buffer_params_t* params, iree_device_size_t allocation_size,
iree_hal_buffer_t** out_buffer) {
iree_hal_xrt_lite_allocator* allocator =
reinterpret_cast<iree_hal_xrt_lite_allocator*>(base_allocator);
// Coerce options into those required by the current device.
iree_hal_buffer_params_t compat_params = *params;
iree_hal_buffer_compatibility_t compatibility = query_buffer_compatibility(
base_allocator, &compat_params, &allocation_size);
iree_hal_buffer_compatibility_t compatibility =
iree_hal_xrt_lite_allocator_query_buffer_compatibility(
base_allocator, &compat_params, &allocation_size);
if (!iree_all_bits_set(compatibility,
IREE_HAL_BUFFER_COMPATIBILITY_ALLOCATABLE)) {
return iree_make_status(
Expand Down Expand Up @@ -104,8 +103,8 @@ iree_status_t allocate_buffer(iree_hal_allocator_t* base_allocator,
return status;
}

void deallocate_buffer(iree_hal_allocator_t* base_allocator,
iree_hal_buffer_t* base_buffer) {
void iree_hal_xrt_lite_allocator_deallocate_buffer(
iree_hal_allocator_t* base_allocator, iree_hal_buffer_t* base_buffer) {
iree_hal_xrt_lite_allocator* allocator =
reinterpret_cast<iree_hal_xrt_lite_allocator*>(base_allocator);
bool was_imported = false;
Expand All @@ -117,12 +116,6 @@ void deallocate_buffer(iree_hal_allocator_t* base_allocator,
iree_hal_buffer_destroy(base_buffer);
}

static iree_hal_xrt_lite_allocator* iree_hal_xrt_lite_allocator_cast(
iree_hal_allocator_t* base_value) {
IREE_HAL_ASSERT_TYPE(base_value, &iree_hal_xrt_lite_allocator_vtable);
return reinterpret_cast<iree_hal_xrt_lite_allocator*>(base_value);
}

iree_status_t iree_hal_xrt_lite_allocator_create(
iree_allocator_t host_allocator, shim_xdna::device* device,
iree_hal_allocator_t** out_allocator) {
Expand Down Expand Up @@ -151,7 +144,7 @@ static void iree_hal_xrt_lite_allocator_destroy(
iree_hal_allocator_t* base_allocator) {
IREE_ASSERT_ARGUMENT(base_allocator);
iree_hal_xrt_lite_allocator* allocator =
iree_hal_xrt_lite_allocator_cast(base_allocator);
reinterpret_cast<iree_hal_xrt_lite_allocator*>(base_allocator);
IREE_TRACE_ZONE_BEGIN(z0);

iree_hal_resource_release(&allocator->resource);
Expand All @@ -173,8 +166,9 @@ const iree_hal_allocator_vtable_t iree_hal_xrt_lite_allocator_vtable = {
.host_allocator = iree_hal_xrt_lite_allocator_host_allocator,
.trim = unimplemented_ok_status,
.query_statistics = unimplemented_ok_void,
.query_buffer_compatibility = query_buffer_compatibility,
.allocate_buffer = allocate_buffer,
.deallocate_buffer = deallocate_buffer,
.query_buffer_compatibility =
iree_hal_xrt_lite_allocator_query_buffer_compatibility,
.allocate_buffer = iree_hal_xrt_lite_allocator_allocate_buffer,
.deallocate_buffer = iree_hal_xrt_lite_allocator_deallocate_buffer,
};
}
8 changes: 0 additions & 8 deletions runtime/src/iree-amd-aie/driver/xrt-lite/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
#include "iree/base/api.h"
#include "iree/hal/api.h"

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

struct iree_hal_xrt_lite_device_options_t {};

IREE_API_EXPORT void iree_hal_xrt_lite_device_options_initialize(
Expand Down Expand Up @@ -41,8 +37,4 @@ IREE_API_EXPORT iree_status_t iree_hal_xrt_lite_device_create(
const struct iree_hal_xrt_lite_device_options_t* options,
iree_allocator_t host_allocator, iree_hal_device_t** out_device);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

#endif // IREE_AMD_AIE_DRIVER_XRT_LITE_API_H_
47 changes: 23 additions & 24 deletions runtime/src/iree-amd-aie/driver/xrt-lite/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ struct iree_hal_xrt_lite_buffer {
iree_hal_buffer_release_callback_t release_callback;
};

iree_status_t invalidate_range(iree_hal_buffer_t* base_buffer,
iree_device_size_t local_byte_offset,
iree_device_size_t local_byte_length) {
iree_status_t iree_hal_xrt_lite_buffer_invalidate_range(
iree_hal_buffer_t* base_buffer, iree_device_size_t local_byte_offset,
iree_device_size_t local_byte_length) {
iree_hal_xrt_lite_buffer* buffer =
reinterpret_cast<iree_hal_xrt_lite_buffer*>(base_buffer);
if (IREE_UNLIKELY(!buffer->bo)) {
Expand All @@ -34,12 +34,11 @@ iree_status_t invalidate_range(iree_hal_buffer_t* base_buffer,
return iree_ok_status();
}

iree_status_t map_range(iree_hal_buffer_t* base_buffer,
iree_hal_mapping_mode_t mapping_mode,
iree_hal_memory_access_t memory_access,
iree_device_size_t local_byte_offset,
iree_device_size_t local_byte_length,
iree_hal_buffer_mapping_t* mapping) {
iree_status_t iree_hal_xrt_lite_buffer_map_range(
iree_hal_buffer_t* base_buffer, iree_hal_mapping_mode_t mapping_mode,
iree_hal_memory_access_t memory_access,
iree_device_size_t local_byte_offset, iree_device_size_t local_byte_length,
iree_hal_buffer_mapping_t* mapping) {
iree_hal_xrt_lite_buffer* buffer =
reinterpret_cast<iree_hal_xrt_lite_buffer*>(base_buffer);
IREE_RETURN_IF_ERROR(iree_hal_buffer_validate_memory_type(
Expand All @@ -57,8 +56,8 @@ iree_status_t map_range(iree_hal_buffer_t* base_buffer,
// Should be guaranteed by previous checks.
IREE_ASSERT(host_ptr != nullptr);
uint8_t* data_ptr = reinterpret_cast<uint8_t*>(host_ptr) + local_byte_offset;
iree_status_t status =
invalidate_range(base_buffer, local_byte_offset, local_byte_length);
iree_status_t status = iree_hal_xrt_lite_buffer_invalidate_range(
base_buffer, local_byte_offset, local_byte_length);
// If we mapped for discard, scribble over the bytes. This is not a mandated
// behavior but it will make debugging issues easier. Alternatively for heap
// buffers we could reallocate them such that ASAN yells, but that would
Expand All @@ -72,9 +71,9 @@ iree_status_t map_range(iree_hal_buffer_t* base_buffer,
return status;
}

iree_status_t flush_range(iree_hal_buffer_t* base_buffer,
iree_device_size_t local_byte_offset,
iree_device_size_t local_byte_length) {
iree_status_t iree_hal_xrt_lite_buffer_flush_range(
iree_hal_buffer_t* base_buffer, iree_device_size_t local_byte_offset,
iree_device_size_t local_byte_length) {
iree_hal_xrt_lite_buffer* buffer =
reinterpret_cast<iree_hal_xrt_lite_buffer*>(base_buffer);
if (IREE_UNLIKELY(!buffer->bo)) {
Expand All @@ -87,11 +86,11 @@ iree_status_t flush_range(iree_hal_buffer_t* base_buffer,
return iree_ok_status();
}

iree_status_t unmap_range(iree_hal_buffer_t* base_buffer,
iree_device_size_t local_byte_offset,
iree_device_size_t local_byte_length,
iree_hal_buffer_mapping_t* mapping) {
return flush_range(base_buffer, local_byte_offset, local_byte_length);
iree_status_t iree_hal_xrt_lite_buffer_unmap_range(
iree_hal_buffer_t* base_buffer, iree_device_size_t local_byte_offset,
iree_device_size_t local_byte_length, iree_hal_buffer_mapping_t* mapping) {
return iree_hal_xrt_lite_buffer_flush_range(base_buffer, local_byte_offset,
local_byte_length);
}

iree_status_t iree_hal_xrt_lite_buffer_wrap(
Expand Down Expand Up @@ -148,9 +147,9 @@ namespace {
const iree_hal_buffer_vtable_t iree_hal_xrt_lite_buffer_vtable = {
.recycle = iree_hal_buffer_recycle,
.destroy = iree_hal_xrt_lite_buffer_destroy,
.map_range = map_range,
.unmap_range = unmap_range,
.invalidate_range = invalidate_range,
.flush_range = flush_range,
.map_range = iree_hal_xrt_lite_buffer_map_range,
.unmap_range = iree_hal_xrt_lite_buffer_unmap_range,
.invalidate_range = iree_hal_xrt_lite_buffer_invalidate_range,
.flush_range = iree_hal_xrt_lite_buffer_flush_range,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ hal.executable.source public @amdaie_fb {
return
}
}
}
}
59 changes: 31 additions & 28 deletions runtime/src/iree-amd-aie/driver/xrt-lite/device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct iree_hal_xrt_lite_device {
}
};

iree_status_t create_executable_cache(
iree_status_t iree_hal_xrt_lite_device_create_executable_cache(
iree_hal_device_t* base_value, iree_string_view_t identifier,
iree_loop_t loop, iree_hal_executable_cache_t** out_executable_cache) {
iree_hal_xrt_lite_device* device =
Expand All @@ -60,7 +60,7 @@ iree_status_t create_executable_cache(
out_executable_cache);
}

iree_status_t create_command_buffer(
iree_status_t iree_hal_xrt_lite_device_create_command_buffer(
iree_hal_device_t* base_value, iree_hal_command_buffer_mode_t mode,
iree_hal_command_category_t command_categories,
iree_hal_queue_affinity_t queue_affinity, iree_host_size_t binding_capacity,
Expand All @@ -76,17 +76,16 @@ iree_status_t create_command_buffer(
&device->block_pool, device->host_allocator_, out_command_buffer);
}

iree_status_t create_semaphore(iree_hal_device_t* base_value,
uint64_t initial_value,
iree_hal_semaphore_flags_t flags,
iree_hal_semaphore_t** out_semaphore) {
iree_status_t iree_hal_xrt_lite_device_create_semaphore(
iree_hal_device_t* base_value, uint64_t initial_value,
iree_hal_semaphore_flags_t flags, iree_hal_semaphore_t** out_semaphore) {
iree_hal_xrt_lite_device* device =
reinterpret_cast<iree_hal_xrt_lite_device*>(base_value);
return iree_hal_xrt_lite_semaphore_create(device->host_allocator_,
initial_value, out_semaphore);
}

iree_status_t queue_execute(
iree_status_t iree_hal_xrt_lite_device_queue_execute(
iree_hal_device_t* base_value, iree_hal_queue_affinity_t queue_affinity,
const iree_hal_semaphore_list_t wait_semaphore_list,
const iree_hal_semaphore_list_t signal_semaphore_list,
Expand Down Expand Up @@ -118,18 +117,19 @@ iree_status_t queue_execute(
return iree_ok_status();
}

void replace_device_allocator(iree_hal_device_t* base_value,
iree_hal_allocator_t* new_allocator) {
void iree_hal_xrt_lite_device_replace_device_allocator(
iree_hal_device_t* base_value, iree_hal_allocator_t* new_allocator) {
iree_hal_allocator_retain(new_allocator);
iree_hal_xrt_lite_device* device =
reinterpret_cast<iree_hal_xrt_lite_device*>(base_value);
iree_hal_allocator_release(device->device_allocator_);
device->device_allocator_ = new_allocator;
}

iree_status_t query_i64(iree_hal_device_t* base_value,
iree_string_view_t category, iree_string_view_t key,
int64_t* out_value) {
iree_status_t iree_hal_xrt_lite_device_query_i64(iree_hal_device_t* base_value,
iree_string_view_t category,
iree_string_view_t key,
int64_t* out_value) {
*out_value = 0;
iree_hal_xrt_lite_device* device =
reinterpret_cast<iree_hal_xrt_lite_device*>(base_value);
Expand All @@ -146,7 +146,7 @@ iree_status_t query_i64(iree_hal_device_t* base_value,
return iree_make_status(IREE_STATUS_UNIMPLEMENTED, "unsupported query");
}

iree_status_t queue_alloca(
iree_status_t iree_hal_xrt_lite_device_queue_alloca(
iree_hal_device_t* base_value, iree_hal_queue_affinity_t queue_affinity,
const iree_hal_semaphore_list_t wait_semaphore_list,
const iree_hal_semaphore_list_t signal_semaphore_list,
Expand All @@ -163,13 +163,13 @@ iree_status_t queue_alloca(
return iree_ok_status();
}

iree_string_view_t id(iree_hal_device_t* base_value) {
iree_string_view_t iree_hal_xrt_lite_device_id(iree_hal_device_t* base_value) {
iree_hal_xrt_lite_device* device =
reinterpret_cast<iree_hal_xrt_lite_device*>(base_value);
return device->identifier;
}

void destroy(iree_hal_device_t* base_value) {
void iree_hal_xrt_lite_device_destroy(iree_hal_device_t* base_value) {
iree_hal_xrt_lite_device* device =
reinterpret_cast<iree_hal_xrt_lite_device*>(base_value);
IREE_TRACE_ZONE_BEGIN(z0);
Expand All @@ -181,12 +181,14 @@ void destroy(iree_hal_device_t* base_value) {
IREE_TRACE_ZONE_END(z0);
};

iree_allocator_t host_allocator(iree_hal_device_t* base_value) {
iree_allocator_t iree_hal_xrt_lite_device_host_allocator(
iree_hal_device_t* base_value) {
iree_hal_xrt_lite_device* device =
reinterpret_cast<iree_hal_xrt_lite_device*>(base_value);
return device->host_allocator_;
}
iree_hal_allocator_t* device_allocator(iree_hal_device_t* base_value) {
iree_hal_allocator_t* iree_hal_xrt_lite_device_device_allocator(
iree_hal_device_t* base_value) {
iree_hal_xrt_lite_device* device =
reinterpret_cast<iree_hal_xrt_lite_device*>(base_value);
return device->device_allocator_;
Expand Down Expand Up @@ -224,17 +226,18 @@ iree_status_t iree_hal_xrt_lite_device_create(

namespace {
const iree_hal_device_vtable_t iree_hal_xrt_lite_device_vtable = {
.destroy = destroy,
.id = id,
.host_allocator = host_allocator,
.device_allocator = device_allocator,
.replace_device_allocator = replace_device_allocator,
.query_i64 = query_i64,
.create_command_buffer = create_command_buffer,
.create_executable_cache = create_executable_cache,
.create_semaphore = create_semaphore,
.queue_alloca = queue_alloca,
.queue_execute = queue_execute,
.destroy = iree_hal_xrt_lite_device_destroy,
.id = iree_hal_xrt_lite_device_id,
.host_allocator = iree_hal_xrt_lite_device_host_allocator,
.device_allocator = iree_hal_xrt_lite_device_device_allocator,
.replace_device_allocator =
iree_hal_xrt_lite_device_replace_device_allocator,
.query_i64 = iree_hal_xrt_lite_device_query_i64,
.create_command_buffer = iree_hal_xrt_lite_device_create_command_buffer,
.create_executable_cache = iree_hal_xrt_lite_device_create_executable_cache,
.create_semaphore = iree_hal_xrt_lite_device_create_semaphore,
.queue_alloca = iree_hal_xrt_lite_device_queue_alloca,
.queue_execute = iree_hal_xrt_lite_device_queue_execute,
.profiling_begin = unimplemented_ok_status,
.profiling_flush = unimplemented_ok_status,
.profiling_end = unimplemented_ok_status,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 The IREE Authors
// Copyright 2024 The IREE Authors
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
12 changes: 2 additions & 10 deletions runtime/src/iree-amd-aie/driver/xrt-lite/direct_command_buffer.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 The IREE Authors
// Copyright 2024 The IREE Authors
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -11,11 +11,7 @@
#include "iree/base/internal/arena.h"
#include "iree/hal/api.h"

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

// |out_command_buffer| must be released by the caller (see
// `out_command_buffer` must be released by the caller (see
// iree_hal_command_buffer_release).
iree_status_t iree_hal_xrt_lite_direct_command_buffer_create(
shim_xdna::device* shim_device, iree_hal_allocator_t* device_allocator,
Expand All @@ -25,8 +21,4 @@ iree_status_t iree_hal_xrt_lite_direct_command_buffer_create(
iree_allocator_t host_allocator,
iree_hal_command_buffer_t** out_command_buffer);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

#endif // IREE_AMD_AIE_DRIVER_XRT_LITE_XRT_LITE_COMMAND_BUFFER_H_
4 changes: 2 additions & 2 deletions runtime/src/iree-amd-aie/driver/xrt-lite/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "iree-amd-aie/driver/xrt-lite/api.h"
#include "util.h"

#define IREE_HAL_XRT_LITE_DEVICE_ID_DEFAULT 0

typedef struct iree_hal_xrt_lite_driver_t {
iree_hal_resource_t resource;
iree_allocator_t host_allocator;
Expand Down Expand Up @@ -69,8 +71,6 @@ static void iree_hal_xrt_lite_driver_destroy(iree_hal_driver_t* base_driver) {
IREE_TRACE_ZONE_END(z0);
}

#define IREE_HAL_XRT_LITE_DEVICE_ID_DEFAULT 0

static iree_status_t iree_hal_xrt_lite_driver_query_available_devices(
iree_hal_driver_t* base_driver, iree_allocator_t host_allocator,
iree_host_size_t* out_device_info_count,
Expand Down
Loading

0 comments on commit 72e2c27

Please sign in to comment.