NVIDIA / cuda-samples

Samples for CUDA Developers which demonstrates features in CUDA Toolkit
Other
6.47k stars 1.83k forks source link

cudaMallocAsync / cudaMalloc different behave on different driver version #293

Open WilliamKyle opened 2 months ago

WilliamKyle commented 2 months ago

Code

cudaMallocAsync

#include <cuda_runtime_api.h>

#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
    void *data;
    cudaStream_t stream_ = 0;
    for (size_t i = 0; i < 32; i++) {
        cudaError_t error = cudaMallocAsync(&data, 1024 * 1024 * 1024, stream_);
        cout << "Gpu use: " << (i + 1) << "G " << cudaGetErrorString(error) << endl;
    }
    getchar();
    return 0;
}

cudaMalloc

#include <cuda_runtime_api.h>

#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
    void *data;
    cudaStream_t stream_ = 0;
    for (size_t i = 0; i < 32; i++) {
        cudaError_t error = cudaMalloc(&data, 1024 * 1024 * 1024);
        cout << "Gpu use: " << (i + 1) << "G " << cudaGetErrorString(error) << endl;
    }
    getchar();
    return 0;
}

Driver Version 536.67

image

No Option CUDA - Sysmem Fallback Policy

image

cudaMallocAsync

image

cudaMalloc

image

Driver Version 551.61

image

Prefer System Fallback

image

cudaMallocAsync

image

cudaMalloc

image

Prefer No System Fallback

image

cudaMallocAsync

image

cudaMalloc

image

cudaMallocAsync has one more failure when get 12G on 551.61 with Prefer System Fallback