{"id":21011584,"url":"https://github.com/zhuzilin/pytorch-malloc","last_synced_at":"2025-05-15T03:32:23.834Z","repository":{"id":85017034,"uuid":"422941531","full_name":"zhuzilin/pytorch-malloc","owner":"zhuzilin","description":"An external memory allocator example for PyTorch.","archived":false,"fork":false,"pushed_at":"2021-11-02T07:59:47.000Z","size":22,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-03T03:22:52.015Z","etag":null,"topics":["memory-allocator","pytorch"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhuzilin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-30T17:01:43.000Z","updated_at":"2024-12-31T10:32:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"5e27546a-743d-4df1-9398-5357eed1aebd","html_url":"https://github.com/zhuzilin/pytorch-malloc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhuzilin%2Fpytorch-malloc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhuzilin%2Fpytorch-malloc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhuzilin%2Fpytorch-malloc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhuzilin%2Fpytorch-malloc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhuzilin","download_url":"https://codeload.github.com/zhuzilin/pytorch-malloc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254266380,"owners_count":22042098,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["memory-allocator","pytorch"],"created_at":"2024-11-19T09:29:37.279Z","updated_at":"2025-05-15T03:32:23.827Z","avatar_url":"https://github.com/zhuzilin.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Custom PyTorch Memory Management\n\nThis is an external memory allocator example for [PyTorch](https://github.com/pytorch/pytorch). The underlying memory allocator is [CNMeM](https://github.com/NVIDIA/cnmem).\n\n## Usage\n\nCompile with `nvcc`:\n\n```bash\ncd pytorch_malloc\nmake\n```\n\nNote that we need `--cudart=none` to prevent linking the static libcudart.so.\n\nFor more information about the nvcc flags: https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html\n\nTo make pytorch allocate without the inherit caching mechanism, run with `PYTORCH_NO_CUDA_MEMORY_CACHING`:\n\n```bash\nLD_PRELOAD=./libcudart.so PYTORCH_NO_CUDA_MEMORY_CACHING=1 python3 your_model.py\n```\n\n## Profile\n\nUse the `profiler` branch to profile the memory usage of your model:\n\n```bash\ngit checkout profiler\nmake\n```\n\nRun the example script with:\n\n```bash\n\u003e LD_PRELOAD=./libcudart.so PYTORCH_NO_CUDA_MEMORY_CACHING=1 python3 torch_example.py\nstart allocate 0\n[Allocator] create allocator\n[Allocator] free mem: 33094893568 B, total mem: 34089730048 B.\n[Allocator] malloc(139996541485056): 64 B, time: 357 us.\nend allocate 0\nstart allocate 1\n[Allocator] malloc(139996541485568): 64 B, time: 639 us.\n[Allocator] free(139996541485056): 64 B, time: 699 us.\nend allocate 1\nstart allocate 2\n[Allocator] malloc(139996541485056): 64 B, time: 754 us.\n[Allocator] free(139996541485568): 64 B, time: 781 us.\nend allocate 2\n[Allocator] free(139996541485056): 64 B, time: 14273 us\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhuzilin%2Fpytorch-malloc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhuzilin%2Fpytorch-malloc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhuzilin%2Fpytorch-malloc/lists"}