Skip to content

Commit

Permalink
[GPUJIT] Make max managed pointers an environment variable.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bollu committed Aug 22, 2017
1 parent a28260f commit 14544a8
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions polly/tools/GPURuntime/GPUJIT.c
Expand Up @@ -30,6 +30,7 @@
#include <dlfcn.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 14544a8

Please sign in to comment.