Skip to content

Conversation

@Ceng23333
Copy link
Collaborator

Signed-off-by: Ceng <441651826@qq.com>
@Ceng23333 Ceng23333 requested review from PanZezhong1725 and YdrMaster and removed request for PanZezhong1725 August 4, 2025 08:13
};

// Represents a vacant region, storing its length.
using infinirtVacantRegion = size_t;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using?这是纯C语言头文件,不能有std之类的C++语法

typedef void *infinirtAllocationHandle_t;

// Represents a physical memory allocation, mirroring Rust's PhyMem.
struct infinirtPhyMem {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct命名首字母大写

@PanZezhong1725
Copy link
Collaborator

先把document写了提pr

// A region in virtual memory can be either mapped or vacant.
using infinirtPhyRegion = std::variant<infinirtMappedRegion, infinirtVacantRegion>;

struct infinirtVirtualMemManager {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个库只提供接口就可以,不需要提供一个manager,用户自己负责管理虚存和物理内存的表

Signed-off-by: Ceng <441651826@qq.com>
Signed-off-by: Ceng <441651826@qq.com>
Signed-off-by: Ceng <441651826@qq.com>
__C __export infiniStatus_t infinirtReleasePhysicalMem(infinirtPhysicalMemoryHandle_t pm_handle);

__C __export infiniStatus_t infinirtCreateVirtualMem(void **vm, size_t len);
__C __export infiniStatus_t infinirtMapVirtualMem(void *vm, size_t len, size_t offset, infinirtPhysicalMemoryHandle_t pm_handle);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

权限控制要暴露吗?

// Virtual memory & physical memory
typedef void *infinirtPhysicalMemoryHandle_t;

__C __export infiniStatus_t infinirtGetMemGranularityMinimum(size_t *granularity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得 CUDA 搞这个名字挺奇怪的,要是想跟 CUDA 对齐就保持,不然的话叫 page size 之类的更好些

return freeDevice(ptr);
}

infiniStatus_t getMemGranularityMinimum(size_t *granularity) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CPU 主存很容易实现虚拟化逻辑,没必要设置为不支持。可以手工做一套用户态虚拟化或者交由操作系统处理(主存正常分配自带操作系统提供的虚拟化)

#include "infinirt_cuda.cuh"
#include <cuda.h>
#include <cuda_runtime.h>
#include <string.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.cu 里面理论上说不需要 cuda.h、cuda_runtime.h 对于 nvcc 来说是预置的。c/c++ 标准库头文件应该用 c++ 标准的

CUmemAllocationProp *getMemProp() {
int device_id;
infinirtGetDevice(nullptr, &device_id);
CUmemAllocationProp *cuda_prop = new CUmemAllocationProp();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这东西为啥在堆上分配啊?没必要啊

}

infiniStatus_t getMemGranularityMinimum(size_t *granularity) {
CUmemAllocationProp *cuda_prop = getMemProp();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里用
CUmemAllocationProp cuda_prop;
getMemProp()可以传它的地址

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants