相当于memalign在cuda中 [英] Equivalent of memalign in cuda

查看:134
本文介绍了相当于memalign在cuda中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CUDA并行化C函数.我注意到有几个结构体被作为指向此函数的指针传递. 使用统一内存视图,我已经确定并修改了malloc()cudaMallocManaged().

I am trying to parallelize a C function using CUDA. I noticed that there are several structs which are being passed as pointers to this function. With the unified memory view, I have identified and modified malloc() to cudaMallocManaged().

但是,现在有一个使用memalign()的分配.我想完成与cudaMallocManaged()一样的任务.

But, now there is a allocation using memalign(). I want to achieve a similar task as that was done by cudaMallocManaged().

是否存在这样的等效项?如果没有,那该怎么办?

Does such an equivalent exists ? If no, then what needs to be done?

这是memalign()分配行的外观:

float *data = (float*) memalign(16, some_integer*sizeof(float));

推荐答案

您应该能够像这样注册现有的主机内存缓冲区:

You should be able to register an existing host memory buffer like this:

float *data = (float*) memalign(16, some_integer*sizeof(float));
cudaHostRegister((void *)data, some_integer*sizeof(float), cudaHostRegisterDefault);

注册data之后的

应该与cudaMallocManaged分配的内存具有相同的行为.检查cudaHostRegister调用的返回值,如果失败,则说明您选择了不兼容的对齐方式.

after registration data should behave the same as memory allocated with cudaMallocManaged. Check the return value from the cudaHostRegister call, if it fails, you have chosen an incompatible alignment.

这篇关于相当于memalign在cuda中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆