Skip to content

PyTorch Memory Not Automatically Pinned

Description

If possible, it is better to rely on automatic pinning in PyTorch to avoid undefined behavior and for efficiency. PyTorch memory not automatically pinned.

Examples

Insecure Code

python
torch.utils.data.DataLoader(dataset, batch_size=32)

Secure Code

python
torch.utils.data.DataLoader(dataset, batch_size=32, pin_memory=True)

Remediation

Use the `pin_memory=True` argument when creating a `DataLoader` to enable automatic memory pinning.

Rule Details

FieldValue
IDCODE-0640
CategoryInsecureConfig
SeverityLOW
CWECWE-676
ConfidenceHIGH
ImpactLOW
LikelihoodLOW
ExploitabilityCOMPLEX
Tagsmemory-pinning, pytorch
OWASPN/A

References