本文介绍了分析我的代码(开源)和第 3 方代码(闭源)的内存使用情况的最佳策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很快将负责对用 C/C++ 编写并使用 CUDA 来利用 GPU 处理的代码进行适当的内存配置.

I am soon going to be tasked with doing a proper memory profile of a code that is written in C/C++ and uses CUDA to take advantage of GPU processing.

我最初的想法是创建宏和运算符重载,以便我在源代码中跟踪对 malloc、free、delete 和 new 的调用.我将能够包含不同的标题,并使用 __FILE__ 和 __LINE__ 宏将内存调用打印到日志文件.这种类型的策略可以在这里找到:http://www.almostinfinite.com/memtrack.html

My initial thoughts would be to create macros and operator overloads that would allow me to track calls to malloc, free, delete, and new calls within my source code. I would just be able to include a different header, and use the __FILE__ and __LINE__ macros to print memory calls to a log file. This type of strategy is found here: http://www.almostinfinite.com/memtrack.html

在第 3 方库中的链接中跟踪该使用情况的最佳方法是什么?我假设我几乎只能在函数调用之前和之后跟踪内存使用情况,对吗?在我的宏/重载场景中,我可以简单地跟踪请求的大小来确定需要多少内存.我怎么能知道 3rd 方库正在使用多少?我的理解也是,跟踪免费"并不能真正让您了解代码在任何特定时间使用了多少,因为它不一定会返回给操作系统.我感谢任何关于此事的讨论.

What is the best way to track that usage in a linked in 3rd party library? I am assuming I'd pretty much only be able to track memory usage before and after the function calls, correct? In my macro/overload scenario, I can simply track the size of the requests to figure out how much memory is being asked for. How would I be able to tell how much the 3rd party lib is using? It is my understanding also, that tracking "free" doesnt really give you any sense of how much the code is using at any particular time, because it is not necessarily returned to the OS. I appreciate any discussion of the matter.

我真的不想使用任何内存分析工具,如 Totalview 或 valgrind, 因为它们通常会做很多其他事情(边界检查等),这似乎会使软件运行得非常慢.另一个原因是我希望这在某种程度上是线程安全的——我相信该软件使用 MPI 来生成进程.我将尝试实时对此进行分析,以便我可以转储到日志文件或其他进程可以读取的内容,以在软件运行时可视化内存使用情况.这也将主要在 linux 环境中运行.

I dont really want to use any memory profiling tools like Totalview or valgrind, because they typically do a lot of other things (bounds checking, etc) that seems to make the software run very slow. Another reason for this is that I want this to be somewhat thread safe - the software uses MPI I believe to spawn processes. I am going to be trying to profile this in real time so I can dump out to log files or something that can be read by another process to visualize memory usage as the software runs. This is also primarily going to be run in a linux environment.

谢谢

推荐答案

也许链接器选项 --wrap=symbol 可以帮助你.真的很好的例子可以在这里找到:man ld

Maybe linker option --wrap=symbol can help you. Really good example can be found here:man ld

这篇关于分析我的代码(开源)和第 3 方代码(闭源)的内存使用情况的最佳策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 05:18