Skip to content

Instantly share code, notes, and snippets.

@dangkhoasdc
Created October 22, 2018 10:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dangkhoasdc/4dfe88ada3b84208e17f488a8a8508db to your computer and use it in GitHub Desktop.
Save dangkhoasdc/4dfe88ada3b84208e17f488a8a8508db to your computer and use it in GitHub Desktop.
cudaDeviceSetLimit example
#include <cudnn.h>
#include <cuda.h>
#include <iostream>
#include <chrono>
#include <thread>
int main(int argc, char const *argv[]) {
// cuda initialization via cudaMalloc
size_t limit = 0;
cudaDeviceGetLimit(&limit, cudaLimitStackSize);
printf("cudaLimitStackSize: %u\n", (unsigned)limit);
cudaDeviceGetLimit(&limit, cudaLimitPrintfFifoSize);
printf("cudaLimitPrintfFifoSize: %u\n", (unsigned)limit);
cudaDeviceGetLimit(&limit, cudaLimitMallocHeapSize);
printf("cudaLimitMallocHeapSize: %u\n", (unsigned)limit);
std::cout << "default settings of cuda context" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(10));
limit = 10;
cudaDeviceSetLimit(cudaLimitStackSize, limit);
cudaDeviceSetLimit(cudaLimitPrintfFifoSize, limit);
cudaDeviceSetLimit(cudaLimitMallocHeapSize, limit);
std::cout << "set limit to 10 for all settings" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(10));
limit = 0;
cudaDeviceGetLimit(&limit, cudaLimitStackSize);
printf("New cudaLimitStackSize: %u\n", (unsigned)limit);
cudaDeviceGetLimit(&limit, cudaLimitPrintfFifoSize);
printf("New cudaLimitPrintfFifoSize: %u\n", (unsigned)limit);
cudaDeviceGetLimit(&limit, cudaLimitMallocHeapSize);
printf("New cudaLimitMallocHeapSize: %u\n", (unsigned)limit);
std::this_thread::sleep_for(std::chrono::seconds(20));
int N = 1;
int *pa;
cudaMalloc((void **)&pa, N*sizeof(int));
std::cout << "Call cudaMalloc to allocate 4 bytes" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(20));
// cudnn handler
cudnnHandle_t cudnn;
cudnnCreate(&cudnn);
std::cout << "Created a cudnn handler" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(20));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment