- 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/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!