Getting Started with msMemScope
Overview
Introduction
msMemScope collects memory events and conducts memory leak detection, memory comparison, memory block monitoring, memory usage breakdown, and inefficient memory identification based on the collected events. This document describes how to use msMemScope and its functions through a simple PyTorch script.
Environment Setup
Refer to msMemScope Installation Guide to install msMemScope.
The following example is designed based on PyTorch and Ascend for PyTorch. Please first download and install Ascend for PyTorch.
Procedure
Set environment variables.
Run the following command as the CANN running user to configure environment variables.
source <cann-path>/Ascend/cann/set_env.shNote:
cann-pathis the CANN installation directory.Run the following command to configure environment variables when using msMemScope to collect memory data.
source <path>/msmemscope/set_env.shNote:
pathis the msMemScope installation directory.Run the following commands to set environment variables to use msMemScope Python APIs.
source msmemscope --load-api-envNote: This command sets the environment variables required for using Python APIs. After use, run the following command to clear them to avoid conflicts with other tools.
source msmemscope --unload-api-env
Access the repository and then run the following command to go to the
exampledirectory.cd ./exampleIn the
exampledirectory, the following code examples are provided:- Python: example_api
- CLI: example_cmd
Use msMemScope in either of the following ways. Python APIs are recommended.
Python APIs
The
config,start,stop, andstepAPIs are provided.API Description config Sets parameters. For parameters not specified, use their default values. start Starts data collection. stop Stops data collection step Fixed information API of step startfor mstx.Run the following command to execute the script:
python example_api.pyCLI: Run the following command to execute the script using msMemScope:
msmemscope --events=alloc,free,access,launch --level=kernel,op --call-stack=c,python --analysis=leaks,inefficient,decompose --output-path=./output --format=csv python ./example_cmd.py
For more information about tool parameters, see Memory Collection.
Check the output result file.
For details about the output file and memory analysis, see Output File Description and Memory Analysis.