[GPUJIT] Make max managed pointers an environment variable.

This was originally a `#define`. It is much easier to play around with
this as an environment variable when we run on large programs.

Differential Revision: https://reviews.llvm.org/D37012

llvm-svn: 311471
This commit is contained in:
Siddharth Bhat 2017-08-22 17:32:27 +00:00
parent a28260f486
commit 14544a8068
1 changed files with 20 additions and 7 deletions

View File

@ -30,6 +30,7 @@
#include <dlfcn.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -1419,21 +1420,33 @@ static void launchKernelCUDA(PollyGPUFunction *Kernel, unsigned int GridDimX,
}
// Maximum number of managed memory pointers.
#define MAX_POINTERS 4000
#define DEFAULT_MAX_POINTERS 4000
// For the rationale behing a list of free pointers, see `polly_freeManaged`.
void *g_managedptrs[MAX_POINTERS];
int g_nmanagedptrs = 0;
void **g_managedptrs;
unsigned long long g_nmanagedptrs = 0;
unsigned long long g_maxmanagedptrs = 0;
__attribute__((constructor)) static void initManagedPtrsBuffer() {
g_maxmanagedptrs = DEFAULT_MAX_POINTERS;
const char *maxManagedPointersString = getenv("POLLY_MAX_MANAGED_POINTERS");
if (maxManagedPointersString)
g_maxmanagedptrs = atoll(maxManagedPointersString);
g_managedptrs = (void **)malloc(sizeof(void *) * g_maxmanagedptrs);
}
// Add a pointer as being allocated by cuMallocManaged
void addManagedPtr(void *mem) {
assert(g_nmanagedptrs < MAX_POINTERS && "We have hit the maximum number of "
"managed pointers allowed. Increase "
"MAX_POINTERS");
assert(g_maxmanagedptrs > 0 && "g_maxmanagedptrs was set to 0!");
assert(g_nmanagedptrs < g_maxmanagedptrs &&
"We have hit the maximum number of "
"managed pointers allowed. Set the "
"POLLY_MAX_MANAGED_POINTERS environment variable. ");
g_managedptrs[g_nmanagedptrs++] = mem;
}
int isManagedPtr(void *mem) {
for (int i = 0; i < g_nmanagedptrs; i++) {
for (unsigned long long i = 0; i < g_nmanagedptrs; i++) {
if (g_managedptrs[i] == mem)
return 1;
}