- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
代码:
// g++ -std=c++17 -O0 -g -Wall -Wextra -lOpenCL query.cpp -o query
// valgrind --leak-check=full --track-origins=yes --tool=memcheck ./query N
#include <CL/cl.h>
#include <CL/cl.hpp>
#include <vector>
#include <string>
#include <iostream>
#include <memory>
using namespace std;
#define CL_CHECK_ERROR(error) \
if ((error) != CL_SUCCESS){ cout << "ERROR in " << __FILE__ << ":" << __LINE__ << "\n"; }
int main(int, char * argv[])
{
int type = stoi(argv[1]);
string info_buffer;
int info_buffer_size = 1024;
info_buffer.reserve(info_buffer_size);
if (type == 0){
vector<cl_platform_id> platforms;
cl_uint num_platforms;
CL_CHECK_ERROR(clGetPlatformIDs(0, NULL, &num_platforms));
cout << "num_platforms: " << num_platforms << "\n";
platforms.reserve(num_platforms);
platforms.resize(num_platforms);
CL_CHECK_ERROR(clGetPlatformIDs(num_platforms, platforms.data(), NULL));
cout << "- " << platforms.data()[0] << "\n";
// cout << "- " << platforms.data()[1] << "\n";
// cout << platforms.size() << "\n";
for (auto& platform : platforms){
cout << platform << "\n";
size_t size;
CL_CHECK_ERROR(clGetPlatformInfo(platform, CL_PLATFORM_NAME, 0, NULL, &size));
info_buffer.resize(size); // works also with size - 1
CL_CHECK_ERROR(clGetPlatformInfo(platform, CL_PLATFORM_NAME, size, info_buffer.data(), NULL));
cout << "platform: '" << info_buffer << "'\n";
}
}else if (type == 1){
cl_uint num_platforms;
CL_CHECK_ERROR(clGetPlatformIDs(0, NULL, &num_platforms));
cout << "num_platforms: " << num_platforms << "\n";
unique_ptr<cl_platform_id[]> platforms(new cl_platform_id[num_platforms]);
CL_CHECK_ERROR(clGetPlatformIDs(num_platforms, platforms.get(), NULL));
cout << "- " << platforms[0] << "\n";
// cout << "- " << platforms[1] << "\n";
for (uint i=0; i<num_platforms; i++){
cl_platform_id platform = platforms[i];
cout << platforms[i] << "\n";
size_t size;
CL_CHECK_ERROR(clGetPlatformInfo(platform, CL_PLATFORM_NAME, 0, NULL, &size));
info_buffer.resize(size); // works also with size - 1
CL_CHECK_ERROR(clGetPlatformInfo(platform, CL_PLATFORM_NAME, size, info_buffer.data(), NULL));
cout << "platform: '" << info_buffer << "'\n";
}
} else {
vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
cout << "num_platforms: " << platforms.size() << "\n";
cout << "- " << platforms.at(0)() << "\n";
// cout << "- " << platforms[1] << "\n";
for (auto& platform : platforms) {
CL_CHECK_ERROR(platform.getInfo(CL_PLATFORM_NAME, &info_buffer));
cout << "platform: " << info_buffer << "\n";
}
}
return 0;
}
编译:
g++ -std=c++17 -O0 -g -Wall -Wextra -lOpenCL query.cpp -o query
瓦尔格林德:
valgrind --leak-check=full --track-origins=yes --tool=memcheck ./query 0 2>query_t0.memcheck
valgrind --leak-check=full --track-origins=yes --tool=memcheck ./query 1 2>query_t1.memcheck
valgrind --leak-check=full --track-origins=yes --tool=memcheck ./query 2 2>query_t2.memcheck
在 t0 和 t1 情况下 (.h):
==8877== LEAK SUMMARY:
==8877== definitely lost: 2,804 bytes in 19 blocks
==8877== indirectly lost: 1,444 bytes in 9 blocks
==8877== possibly lost: 152 bytes in 1 blocks
==8877== still reachable: 3,056,953 bytes in 1,706 blocks
==8877== of which reachable via heuristic:
==8877== newarray : 7,192 bytes in 7 blocks
==8877== suppressed: 0 bytes in 0 blocks
==8877== Reachable blocks (those to which a pointer was found) are not shown.
==8877== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==8877==
==8877== For counts of detected and suppressed errors, rerun with: -v
==8877== ERROR SUMMARY: 231 errors from 76 contexts (suppressed: 1 from 1)
在 t2 (.hpp) 中:
==32316== LEAK SUMMARY:
==32316== definitely lost: 2,956 bytes in 20 blocks
==32316== indirectly lost: 1,444 bytes in 9 blocks
==32316== possibly lost: 0 bytes in 0 blocks
==32316== still reachable: 3,056,953 bytes in 1,706 blocks
==32316== of which reachable via heuristic:
==32316== newarray : 7,192 bytes in 7 blocks
==32316== suppressed: 0 bytes in 0 blocks
==32316== Reachable blocks (those to which a pointer was found) are not shown.
==32316== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==32316==
==32316== For counts of detected and suppressed errors, rerun with: -v
==32316== ERROR SUMMARY: 230 errors from 75 contexts (suppressed: 1 from 1)
一些错误(来自 t2):
==32316== 168 (144 direct, 24 indirect) bytes in 1 blocks are definitely lost in loss record 1,201 of 1,366
==32316== at 0x4C2CEBF: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32316== by 0xB4DDF64: Priv_Main_Control_Refresh() (in /usr/lib/libatiadlxx.so)
==32316== by 0xB4E669F: ADL_Main_Control_Refresh_X() (in /usr/lib/libatiadlxx.so)
==32316== by 0xB4F3073: ADL2_Main_Control_Refresh (in /usr/lib/libatiadlxx.so)
==32316== by 0xB4F58E1: ADL2_Main_Control_Create (in /usr/lib/libatiadlxx.so)
==32316== by 0x7A50470: ??? (in /usr/lib/libamdocl64.so)
==32316== by 0x7D6F340: ??? (in /usr/lib/libamdocl64.so)
==32316== by 0x7D3F8C6: ??? (in /usr/lib/libamdocl64.so)
==32316== by 0x7D3F91B: ??? (in /usr/lib/libamdocl64.so)
==32316== by 0x7D44C73: ??? (in /usr/lib/libamdocl64.so)
==32316== by 0x7D2E7C6: ??? (in /usr/lib/libamdocl64.so)
==32316== by 0x7A27F26: ??? (in /usr/lib/libamdocl64.so)
==32316==
==32316== 278 (240 direct, 38 indirect) bytes in 1 blocks are definitely lost in loss record 1,225 of 1,366
==32316== at 0x4C2D51F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32316== by 0x63C2DD7: ??? (in /opt/intel/opencl-runtime/lib64/libintelocl.so)
==32316== by 0x6339563: ??? (in /opt/intel/opencl-runtime/lib64/libintelocl.so)
==32316== by 0x6339F61: ??? (in /opt/intel/opencl-runtime/lib64/libintelocl.so)
==32316== by 0x634FD84: clGetPlatformIDs (in /opt/intel/opencl-runtime/lib64/libintelocl.so)
==32316== by 0x4E3EBD1: ??? (in /usr/lib/libOpenCL.so.1.0.0)
==32316== by 0x4E3FE83: clGetPlatformIDs (in /usr/lib/libOpenCL.so.1.0.0)
==32316== by 0x10B77C: cl::Platform::get(std::vector<cl::Platform, std::allocator<cl::Platform> >*) (cl.hpp:2338)
==32316== by 0x10B143: main (query.cpp:69)
==32316==
==32316== 286 (248 direct, 38 indirect) bytes in 1 blocks are definitely lost in loss record 1,227 of 1,366
==32316== at 0x4C2D51F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32316== by 0x63C2F09: ??? (in /opt/intel/opencl-runtime/lib64/libintelocl.so)
==32316== by 0x6339563: ??? (in /opt/intel/opencl-runtime/lib64/libintelocl.so)
==32316== by 0x6339F61: ??? (in /opt/intel/opencl-runtime/lib64/libintelocl.so)
==32316== by 0x634FD84: clGetPlatformIDs (in /opt/intel/opencl-runtime/lib64/libintelocl.so)
==32316== by 0x4E3EBD1: ??? (in /usr/lib/libOpenCL.so.1.0.0)
==32316== by 0x4E3FE83: clGetPlatformIDs (in /usr/lib/libOpenCL.so.1.0.0)
==32316== by 0x10B77C: cl::Platform::get(std::vector<cl::Platform, std::allocator<cl::Platform> >*) (cl.hpp:2338)
==32316== by 0x10B143: main (query.cpp:69)
==32316==
==32316== 512 bytes in 1 blocks are definitely lost in loss record 1,252 of 1,366
==32316== at 0x4C2D51F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32316== by 0x63EEAA5: ??? (in /opt/intel/opencl-runtime/lib64/libintelocl.so)
==32316== by 0x63F4526: ??? (in /opt/intel/opencl-runtime/lib64/libintelocl.so)
==32316== by 0x63F4B73: ??? (in /opt/intel/opencl-runtime/lib64/libintelocl.so)
==32316== by 0x6339486: ??? (in /opt/intel/opencl-runtime/lib64/libintelocl.so)
==32316== by 0x6339F61: ??? (in /opt/intel/opencl-runtime/lib64/libintelocl.so)
==32316== by 0x634FD84: clGetPlatformIDs (in /opt/intel/opencl-runtime/lib64/libintelocl.so)
==32316== by 0x4E3EBD1: ??? (in /usr/lib/libOpenCL.so.1.0.0)
==32316== by 0x4E3FE83: clGetPlatformIDs (in /usr/lib/libOpenCL.so.1.0.0)
==32316== by 0x10B77C: cl::Platform::get(std::vector<cl::Platform, std::allocator<cl::Platform> >*) (cl.hpp:2338)
==32316== by 0x10B143: main (query.cpp:69)
==32316==
==32316== 1,520 bytes in 10 blocks are definitely lost in loss record 1,290 of 1,366
==32316== at 0x4C2CEBF: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32316== by 0xD45BEBD: amdcl::scCompileImpl::Text2Stream(amdcl::_il_string_rec const&, amdcl::_il_binary_rec&) (in /usr/lib/libamdocl12cl64.so)
==32316== by 0xD463218: amdcl::AMDIL::toBinary(char const*, unsigned long*) (in /usr/lib/libamdocl12cl64.so)
==32316== by 0xD4646BD: amdcl::AMDIL::compile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, amdcl::scCompileBase*) (in /usr/lib/libamdocl12cl64.so)
==32316== by 0xD46306F: amdcl::AMDIL::compile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) (in /usr/lib/libamdocl12cl64.so)
==32316== by 0xCF80AB3: AMDILFEToISA(_acl_loader_data_0_8**, char const*, unsigned long) (in /usr/lib/libamdocl12cl64.so)
==32316== by 0xCF828B4: if_aclCompile(_acl_compiler_rec_0_8_1*, _acl_bif_rec_0_8_1*, char const*, _acl_type_enum_0_8, _acl_type_enum_0_8, void (*)(char const*, unsigned long)) (in /usr/lib/libamdocl12cl64.so)
==32316== by 0x82C35D8: aclCompile (in /usr/lib/libamdocl64.so)
==32316== by 0x79930E7: ??? (in /usr/lib/libamdocl64.so)
==32316== by 0x799375F: ??? (in /usr/lib/libamdocl64.so)
==32316== by 0x79A2111: ??? (in /usr/lib/libamdocl64.so)
==32316== by 0x79A4929: ??? (in /usr/lib/libamdocl64.so)
如您所见,我尝试了三种不同的方式来查询平台(t0、t1 使用 C API,t2 使用 C++ API)。如何消除代码中的内存泄漏?我做错了什么吗?
从来自 76 个上下文的 231 个错误中,我的文件仅出现在 4 (C) 或 3 (C++) 条消息中(grep 'cpp' query_t1.memcheck
vs grep 'lost' query_t1 .memcheck
).那么,如果我的代码没有泄漏,我该如何消除这些内存泄漏呢?我可以在那里做点什么吗?
例子:
==32316== by 0x10B143: main (query.cpp:69)
==32316== by 0x10B143: main (query.cpp:69)
==32316== by 0x10B143: main (query.cpp:69)
==32316== 8 bytes in 1 blocks are definitely lost in loss record 53 of 1,366
==32316== 8 bytes in 1 blocks are definitely lost in loss record 54 of 1,366
==32316== 8 bytes in 1 blocks are definitely lost in loss record 55 of 1,366
==32316== 8 bytes in 1 blocks are definitely lost in loss record 56 of 1,366
==32316== 20 bytes in 1 blocks are definitely lost in loss record 94 of 1,366
==32316== 168 (144 direct, 24 indirect) bytes in 1 blocks are definitely lost in loss record 1,201 of 1,366
==32316== 278 (240 direct, 38 indirect) bytes in 1 blocks are definitely lost in loss record 1,225 of 1,366
==32316== 286 (248 direct, 38 indirect) bytes in 1 blocks are definitely lost in loss record 1,227 of 1,366
==32316== 512 bytes in 1 blocks are definitely lost in loss record 1,252 of 1,366
==32316== 1,520 bytes in 10 blocks are definitely lost in loss record 1,290 of 1,366
==32316== 1,584 (240 direct, 1,344 indirect) bytes in 1 blocks are definitely lost in loss record 1,291 of 1,366
==32316== definitely lost: 2,956 bytes in 20 blocks
==32316== indirectly lost: 1,444 bytes in 9 blocks
==32316== possibly lost: 0 bytes in 0 blocks
最佳答案
在 valgrind 中使用 pocl git master 运行你的程序,结果:
==21413== Memcheck, a memory error detector
==21413== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==21413== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==21413== Command: ./query 1
==21413==
num_platforms: 1
- 0x840df40
0x840df40
platform: 'Portable Computing Language'
==21413==
==21413== HEAP SUMMARY:
==21413== in use at exit: 74,145 bytes in 858 blocks
==21413== total heap usage: 1,058 allocs, 200 frees, 421,333 bytes allocated
==21413==
==21413== LEAK SUMMARY:
==21413== definitely lost: 0 bytes in 0 blocks
==21413== indirectly lost: 0 bytes in 0 blocks
==21413== possibly lost: 0 bytes in 0 blocks
==21413== still reachable: 74,145 bytes in 858 blocks
==21413== suppressed: 0 bytes in 0 blocks
==21413== Reachable blocks (those to which a pointer was found) are not shown.
==21413== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==21413==
==21413== For counts of detected and suppressed errors, rerun with: -v
==21413== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
所以...
How can I remove the memory leaks in my code? Am I doing something wrong?
你没有做错任何事。 AMD/Intel 实现并不完全没有 memleak:)
关于c++ - OpenCL clGetPlatformIDs 给出大约 230 个 valgrind memcheck 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47869162/
valgrind quickstart page提到: Try to make your program so clean that Memcheck reports no errors. Once
cuda-memcheck 正在报告 Release模式 CUDA 内核的此信息: ========= Error: process didn't terminate successfully ===
我正在使用共享内存运行以下代码: __global__ void computeAddShared(int *in , int *out, int sizeInput){ //not
假设我正在使用一个使用 glibc 的库。当我在通过 Valgrind 运行程序时退出程序时,Valgrind 会检测到各种内存泄漏。我 100% 确定没有任何泄漏与我刚刚编写的几行代码明确相关。有没
我用以下 C 代码引入了内存错误: #include #include int main(int argc, char** argv){ int i; int *a = (int *)malloc
所以在我的程序中,我有一个连续的对象数组。我这样做是因为我想要这些对象中的每一个之间的空间局部性。它们非常小,位于一个非常大的数组中,并按顺序迭代。 因此我这样初始化它们 memoryPool = n
运行我的程序,出现此错误: ==3205== Invalid write of size 8 ==3205== at 0x40167C: push (load.c:75) ==3205==
我正在调试一个链接到商业 API 库(在 Linux 下)的程序。我正在使用 valgrind memcheck,因为我遇到了奇怪的行为,这可能是由于写入超出了分配的内存块所致: valgrind -
我成功地使用 cuda-memcheck 获取有关错误内存访问的错误。使用 -g -G 编译 cuda 代码给出了很好的源位置,如下所示: ========= Error: process didn'
我不认为有一种方法可以像使用 callgrind 那样以编程方式启用/禁用 Valgrind memcheck? (开始/停止检测)。 这是痛苦的,慢得无法使用(如果你想测试的代码自动启动并且你只是让
我试图调试我的 CUDA-C 程序,我发现 cuda-memcheck 可能会有所帮助。我的问题是我无法使用该工具,因为每次运行它时,即使在从互联网上获取的“Hello World”程序上,我也会得到
由于 OpenSSL 使用未初始化的内存,因此对使用 openldap2 的 libldap 的程序进行 Valgrind 是一件苦差事。存在一个 --ignore-fn选项,但仅适用于 Valgri
这是我的代码。 #include #include #include char buf1[100]; char buf2[100]; int main() { char **p = (c
我以前没有使用过 valgrind,但我认为它应该可以检测到一些内存错误。 我的代码: #include unsigned int a[2]; int main() { a[-1] = 21
我正在使用 valgrind 检查我的程序是否在类所需的内存范围内。当我运行 massif 时,我得到一个漂亮的图表,上面显示我的最大内存使用量(堆+堆栈)是 21 KB。当我运行 valgrind
我跑到 cuda-memcheck 调试我的代码,输出如下 ========= Program hit cudaErrorCudartUnloading (error 29) due to "driv
我是编程新手,正在学习 http://c.learncodethehardway.org/book/ex4.html 上的教程它向您展示了如何安装 valgrind。我已经编译了应该显示内存泄漏的示例
我正在使用 Valgrind 工具来了解不同类型的内存泄漏:直接丢失,间接丢失仍然可达并且可能丢失。示例 1: #include #include main() { int *p, i;
我正在从头开始用 C 编写一个计算器(家庭作业)并且在某处遇到内存问题..算法运行完美,但我得到了一组 Valgrind 错误/警告,例如: echo -n "1" | valgrind ./a.ou
我使用 massif、sgcheck 和 memcheck valgrind 的模块来检查 c/c++ 项目。我想知道是否可以让 valgrind 忽略部分代码。当我在我的项目上运行它时,opencv
我是一名优秀的程序员,十分优秀!