-
Notifications
You must be signed in to change notification settings - Fork 31
Add virtual-memory based allocator #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mawad-amd
wants to merge
20
commits into
main
Choose a base branch
from
muhaawad/vmem-allocator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
30e6765
Update dev container
mawad-amd 91e83fe
Add CPM.cmake
mawad-amd 0ecb567
Add vmem allocator
mawad-amd 5211f81
Add bindings
mawad-amd 6a3adf2
Add DMA BUF helper
mawad-amd 060cf43
Add fd sender helper
mawad-amd b71074d
Add wrapper for C Array
mawad-amd 73fca97
Add new allocator
mawad-amd 6b90267
Update project setup
mawad-amd f20c4ae
Add ROCm bug workaround
mawad-amd 3f3a12c
Fix linter issues
mawad-amd 6842b2c
Apply Ruff auto-fixes
github-actions[bot] dc5584a
Fix ssh helper script
mawad-amd 1623500
Add import tests
mawad-amd abd9264
Apply Ruff auto-fixes
github-actions[bot] 31faf1b
Rename to as symmetric
mawad-amd 80efc06
Rename to as symmetric
mawad-amd 105bec1
Apply Ruff auto-fixes
github-actions[bot] 360aa04
Remove old file
mawad-amd 790f199
Fixing tests
mawad-amd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| # Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved. | ||
|
|
||
| cmake_minimum_required(VERSION 3.21) | ||
| project(iris_vmem LANGUAGES CXX HIP) | ||
|
|
||
| # CPM for dependency management | ||
| include(cmake/CPM.cmake) | ||
|
|
||
| # Find required packages | ||
| find_package(Python3 REQUIRED COMPONENTS Interpreter Development) | ||
| find_package(hip REQUIRED) | ||
|
|
||
| # Use CPM to fetch pybind11 | ||
| CPMAddPackage( | ||
| NAME pybind11 | ||
| GITHUB_REPOSITORY pybind/pybind11 | ||
| GIT_TAG v2.11.1 | ||
| ) | ||
|
|
||
| # Use CPM to fetch fmt | ||
| CPMAddPackage( | ||
| NAME fmt | ||
| GITHUB_REPOSITORY fmtlib/fmt | ||
| GIT_TAG 10.2.1 | ||
| ) | ||
|
|
||
| # Create Python module | ||
| pybind11_add_module(_iris_vmem csrc/src/bindings.cpp) | ||
|
|
||
| # Set include directories | ||
| target_include_directories(_iris_vmem PRIVATE | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/csrc/include | ||
| ${Python3_INCLUDE_DIRS} | ||
| ) | ||
|
|
||
| # Link libraries | ||
| target_link_libraries(_iris_vmem PRIVATE | ||
| hip::host | ||
| fmt::fmt | ||
| ) | ||
|
|
||
| # Set C++ standard | ||
| set_target_properties(_iris_vmem PROPERTIES | ||
| CXX_STANDARD 20 | ||
| CXX_STANDARD_REQUIRED ON | ||
| POSITION_INDEPENDENT_CODE ON | ||
| ) | ||
|
|
||
| # Install target | ||
| install(TARGETS _iris_vmem | ||
| LIBRARY DESTINATION iris | ||
| ) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| # | ||
| # SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors | ||
|
|
||
| set(CPM_DOWNLOAD_VERSION 0.42.0) | ||
| set(CPM_HASH_SUM "2020b4fc42dba44817983e06342e682ecfc3d2f484a581f11cc5731fbe4dce8a") | ||
|
|
||
| if(CPM_SOURCE_CACHE) | ||
| set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") | ||
| elseif(DEFINED ENV{CPM_SOURCE_CACHE}) | ||
| set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") | ||
| else() | ||
| set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") | ||
| endif() | ||
|
|
||
| # Expand relative path. This is important if the provided path contains a tilde (~) | ||
| get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) | ||
|
|
||
| file(DOWNLOAD | ||
| https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake | ||
| ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} | ||
| ) | ||
|
|
||
| include(${CPM_DOWNLOAD_LOCATION}) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <Python.h> | ||
| #include <hip/hip_runtime.h> | ||
| #include <memory_resource> | ||
| #include <stdexcept> | ||
| #include <string> | ||
|
|
||
| namespace iris { | ||
| namespace gpu_array { | ||
|
|
||
| // Structure to hold GPU Array Interface data (__cuda_array_interface__ compatible) | ||
| struct GpuArrayInterface { | ||
| void* data; // Device pointer | ||
| int64_t* shape; // Shape array | ||
| int64_t* strides; // Strides array (in bytes) | ||
| int ndim; // Number of dimensions | ||
| std::string typestr; // Data type string (e.g., "<f4" for float32) | ||
| int version; // Interface version (3) | ||
|
|
||
| // Cleanup | ||
| ~GpuArrayInterface() { | ||
| if (shape) delete[] shape; | ||
| if (strides) delete[] strides; | ||
| } | ||
| }; | ||
|
|
||
| // Context for managing lifetime of GPU array interface objects | ||
| struct GpuArrayContext { | ||
| std::pmr::memory_resource* allocator; // Pointer to allocator | ||
| void* data_ptr; // Device pointer | ||
| size_t size; // Allocation size in bytes | ||
| GpuArrayInterface* interface; // Interface struct | ||
|
|
||
| ~GpuArrayContext() { | ||
| if (interface) delete interface; | ||
| } | ||
| }; | ||
|
|
||
| // Convert dtype string to GPU Array Interface typestr | ||
| // Format: <endianness><type><size> | ||
| // endianness: < (little), > (big), | (not applicable) | ||
| // type: i (int), u (uint), f (float), c (complex) | ||
| // size: bytes per element | ||
| inline std::string dtype_to_typestr(const std::string& dtype_str) { | ||
| if (dtype_str == "int32") return "<i4"; | ||
| if (dtype_str == "int64") return "<i8"; | ||
| if (dtype_str == "float32") return "<f4"; | ||
| if (dtype_str == "float64") return "<f8"; | ||
| if (dtype_str == "uint32") return "<u4"; | ||
| if (dtype_str == "uint64") return "<u8"; | ||
| throw std::runtime_error("Unsupported dtype: " + dtype_str); | ||
| } | ||
|
|
||
| // Get element size from dtype string | ||
| inline size_t get_element_size(const std::string& dtype_str) { | ||
| if (dtype_str == "int32" || dtype_str == "uint32" || dtype_str == "float32") return 4; | ||
| if (dtype_str == "int64" || dtype_str == "uint64" || dtype_str == "float64") return 8; | ||
| throw std::runtime_error("Unknown dtype: " + dtype_str); | ||
| } | ||
|
|
||
| // Compute row-major strides (in bytes) | ||
| inline void compute_strides(int64_t* strides, const int64_t* shape, int ndim, size_t element_size) { | ||
| int64_t stride = element_size; | ||
| for (int i = ndim - 1; i >= 0; --i) { | ||
| strides[i] = stride; | ||
| stride *= shape[i]; | ||
| } | ||
| } | ||
|
|
||
| // Create Python dict for __cuda_array_interface__ | ||
| inline PyObject* create_gpu_array_interface_dict( | ||
| void* data_ptr, | ||
| const int64_t* shape, | ||
| int ndim, | ||
| const std::string& typestr, | ||
| bool readonly = false | ||
| ) { | ||
| PyObject* dict = PyDict_New(); | ||
| if (!dict) { | ||
| throw std::runtime_error("Failed to create dict"); | ||
| } | ||
|
|
||
| // shape: tuple of ints | ||
| PyObject* shape_tuple = PyTuple_New(ndim); | ||
| for (int i = 0; i < ndim; ++i) { | ||
| PyTuple_SetItem(shape_tuple, i, PyLong_FromLongLong(shape[i])); | ||
| } | ||
| PyDict_SetItemString(dict, "shape", shape_tuple); | ||
| Py_DECREF(shape_tuple); | ||
|
|
||
| // typestr: string | ||
| PyObject* typestr_obj = PyUnicode_FromString(typestr.c_str()); | ||
| PyDict_SetItemString(dict, "typestr", typestr_obj); | ||
| Py_DECREF(typestr_obj); | ||
|
|
||
| // data: tuple (pointer, readonly) | ||
| PyObject* data_tuple = PyTuple_New(2); | ||
| PyTuple_SetItem(data_tuple, 0, PyLong_FromVoidPtr(data_ptr)); | ||
| PyTuple_SetItem(data_tuple, 1, PyBool_FromLong(readonly ? 1 : 0)); | ||
| PyDict_SetItemString(dict, "data", data_tuple); | ||
| Py_DECREF(data_tuple); | ||
|
|
||
| // version: int (should be 3) | ||
| PyObject* version_obj = PyLong_FromLong(3); | ||
| PyDict_SetItemString(dict, "version", version_obj); | ||
| Py_DECREF(version_obj); | ||
|
|
||
| // strides: None for C-contiguous (optional, can compute if needed) | ||
| Py_INCREF(Py_None); | ||
| PyDict_SetItemString(dict, "strides", Py_None); | ||
|
|
||
| // descr: None for simple types (optional) | ||
| Py_INCREF(Py_None); | ||
| PyDict_SetItemString(dict, "descr", Py_None); | ||
|
|
||
| return dict; | ||
| } | ||
|
|
||
| } // namespace gpu_array | ||
| } // namespace iris |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The remoteUser has been changed from "vscode" to "root". Running containers as root is a security risk and goes against container best practices. Unless there's a specific requirement for root access, consider using a non-root user with appropriate permissions instead.