OPENCL-如何使辅助功能返回阵列并将内存的部分从恒定内存空间转移到私有
OpenCL - how to make helper function return array and transfer portion of memory from constant memory space to private
我有以下功能:
float* get_value(__constant float * A){
float temp[2];
temp[0] = A[0];
temp[1] = A[1];
printf("A[0]: %.2f, temp[0]: %.2f",A[0],temp[0]);
return temp;
}
__kernel
void matmul(__constant float * A){
float * vec1 = get_value(A);
.
.
.
}
在此方法中,正如代码本身所解释的那样,我试图将数组从辅助函数返回到核心,以称为内核。我分配temp[0] = A[0];
的行显然由于某种原因无法工作。但是,openclc确实发出了警告
warning: address of stack memory associated with local variable
'array' returned [-Wreturn-stack-address]
有人可以解释返回与本地内存空间相关的数组的地址时出了什么问题吗?
预先感谢。
您不能(这不是严格的OPENCL问题,这是由于以下事实:函数中的临时变量在离开功能时会"消失",因此返回指针对于您的本地变量,现在指向"不应该使用的东西",并且编译器正确识别了这一点(
使用将数组传递到get_value
的构造,类似于:
float vec1[2];
get_value(A, vec1);
并使get_value
这样的内容:
float* get_value(__constant float * A, private float *res){
res[0] = A[0];
res[1] = A[1];
}
相关文章:
- 当注入程序的内存空间时,如何读取从 0 到 0xFFFFFFFFF 的每个字节?我正在创建模式扫描仪
- 为什么不同的翻译单元没有独立和沙盒的内存空间?
- 我的boost managed_shared_memory在离开作用域时似乎不会从内存空间中取消映射
- 是否可以在专用内存空间中分配一个为提升管理共享内存而创建的对象
- 为什么我只能在 4 GB 的虚拟内存空间上分配 2 GB?
- OPENCL-如何使辅助功能返回阵列并将内存的部分从恒定内存空间转移到私有
- 为多维数组创建内存空间
- 将节点添加到链接列表中,而无需明确分配内存空间(无需使用新)
- 内存空间的反转方向?
- 打开文件*以增加内存空间
- 为什么堆栈中的函数局部变量之间存在内存空间
- 只有当声明一个对象时,内存空间才会分配给类的数据成员,那么为什么 Sizeof(class_name) 给我结果
- 何时分配C++类的成员函数的内存空间
- 使用free()释放new分配的内存空间
- 共享内存空间可以将数据(非POD)发送到另一个共享内存吗?
- 删除内存空间后,指针的值保持不变还是更改?对象内容是否将被更改
- 如何在分配更多内存空间之前检查指针是否为 NULL
- 需要析构函数来释放内存空间,即使所有项目都已弹出
- 数组的指针,该数组的每个元素的内存空间信息存储在哪里
- C++内存空间