2015-04-27 20:02:36 +08:00
|
|
|
/******************** GPUJIT.c - GPUJIT Execution Engine **********************/
|
2012-06-11 17:25:01 +08:00
|
|
|
/* */
|
|
|
|
/* The LLVM Compiler Infrastructure */
|
|
|
|
/* */
|
2012-07-06 18:40:15 +08:00
|
|
|
/* This file is dual licensed under the MIT and the University of Illinois */
|
2015-04-27 20:02:36 +08:00
|
|
|
/* Open Source License. See LICENSE.TXT for details. */
|
2012-06-11 17:25:01 +08:00
|
|
|
/* */
|
|
|
|
/******************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* This file implements GPUJIT, a ptx string execution engine for GPU. */
|
|
|
|
/* */
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
#include "GPUJIT.h"
|
2012-07-05 05:45:03 +08:00
|
|
|
#include <cuda.h>
|
|
|
|
#include <cuda_runtime.h>
|
2012-06-11 17:25:01 +08:00
|
|
|
#include <dlfcn.h>
|
2016-07-06 11:04:47 +08:00
|
|
|
#include <stdarg.h>
|
2012-06-11 17:25:01 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-07-06 11:04:47 +08:00
|
|
|
static int DebugMode;
|
|
|
|
|
|
|
|
static void debug_print(const char *format, ...) {
|
|
|
|
if (!DebugMode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
#define dump_function() debug_print("-> %s\n", __func__)
|
|
|
|
|
2012-07-05 05:45:03 +08:00
|
|
|
/* Define Polly's GPGPU data types. */
|
|
|
|
struct PollyGPUContextT {
|
|
|
|
CUcontext Cuda;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PollyGPUModuleT {
|
|
|
|
CUmodule Cuda;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PollyGPUFunctionT {
|
|
|
|
CUfunction Cuda;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PollyGPUDevicePtrT {
|
|
|
|
CUdeviceptr Cuda;
|
|
|
|
};
|
|
|
|
|
2012-06-11 17:25:01 +08:00
|
|
|
/* Dynamic library handles for the CUDA and CUDA runtime library. */
|
|
|
|
static void *HandleCuda;
|
|
|
|
static void *HandleCudaRT;
|
|
|
|
|
|
|
|
/* Type-defines of function pointer to CUDA driver APIs. */
|
|
|
|
typedef CUresult CUDAAPI CuMemAllocFcnTy(CUdeviceptr *, size_t);
|
|
|
|
static CuMemAllocFcnTy *CuMemAllocFcnPtr;
|
|
|
|
|
|
|
|
typedef CUresult CUDAAPI CuFuncSetBlockShapeFcnTy(CUfunction, int, int, int);
|
|
|
|
static CuFuncSetBlockShapeFcnTy *CuFuncSetBlockShapeFcnPtr;
|
|
|
|
|
2016-03-08 15:34:58 +08:00
|
|
|
typedef CUresult CUDAAPI CuParamSetvFcnTy(CUfunction, int, void *,
|
|
|
|
unsigned int);
|
2012-06-11 17:25:01 +08:00
|
|
|
static CuParamSetvFcnTy *CuParamSetvFcnPtr;
|
|
|
|
|
|
|
|
typedef CUresult CUDAAPI CuParamSetSizeFcnTy(CUfunction, unsigned int);
|
|
|
|
static CuParamSetSizeFcnTy *CuParamSetSizeFcnPtr;
|
|
|
|
|
|
|
|
typedef CUresult CUDAAPI CuLaunchGridFcnTy(CUfunction, int, int);
|
|
|
|
static CuLaunchGridFcnTy *CuLaunchGridFcnPtr;
|
|
|
|
|
|
|
|
typedef CUresult CUDAAPI CuMemcpyDtoHFcnTy(void *, CUdeviceptr, size_t);
|
|
|
|
static CuMemcpyDtoHFcnTy *CuMemcpyDtoHFcnPtr;
|
|
|
|
|
|
|
|
typedef CUresult CUDAAPI CuMemcpyHtoDFcnTy(CUdeviceptr, const void *, size_t);
|
|
|
|
static CuMemcpyHtoDFcnTy *CuMemcpyHtoDFcnPtr;
|
|
|
|
|
|
|
|
typedef CUresult CUDAAPI CuMemFreeFcnTy(CUdeviceptr);
|
|
|
|
static CuMemFreeFcnTy *CuMemFreeFcnPtr;
|
|
|
|
|
|
|
|
typedef CUresult CUDAAPI CuModuleUnloadFcnTy(CUmodule);
|
|
|
|
static CuModuleUnloadFcnTy *CuModuleUnloadFcnPtr;
|
|
|
|
|
|
|
|
typedef CUresult CUDAAPI CuCtxDestroyFcnTy(CUcontext);
|
|
|
|
static CuCtxDestroyFcnTy *CuCtxDestroyFcnPtr;
|
|
|
|
|
|
|
|
typedef CUresult CUDAAPI CuInitFcnTy(unsigned int);
|
|
|
|
static CuInitFcnTy *CuInitFcnPtr;
|
|
|
|
|
|
|
|
typedef CUresult CUDAAPI CuDeviceGetCountFcnTy(int *);
|
|
|
|
static CuDeviceGetCountFcnTy *CuDeviceGetCountFcnPtr;
|
|
|
|
|
|
|
|
typedef CUresult CUDAAPI CuCtxCreateFcnTy(CUcontext *, unsigned int, CUdevice);
|
|
|
|
static CuCtxCreateFcnTy *CuCtxCreateFcnPtr;
|
|
|
|
|
|
|
|
typedef CUresult CUDAAPI CuDeviceGetFcnTy(CUdevice *, int);
|
|
|
|
static CuDeviceGetFcnTy *CuDeviceGetFcnPtr;
|
|
|
|
|
2016-03-08 15:34:58 +08:00
|
|
|
typedef CUresult CUDAAPI CuModuleLoadDataExFcnTy(CUmodule *, const void *,
|
|
|
|
unsigned int, CUjit_option *,
|
|
|
|
void **);
|
2012-06-11 17:25:01 +08:00
|
|
|
static CuModuleLoadDataExFcnTy *CuModuleLoadDataExFcnPtr;
|
|
|
|
|
2016-03-08 15:34:58 +08:00
|
|
|
typedef CUresult CUDAAPI CuModuleGetFunctionFcnTy(CUfunction *, CUmodule,
|
|
|
|
const char *);
|
2012-06-11 17:25:01 +08:00
|
|
|
static CuModuleGetFunctionFcnTy *CuModuleGetFunctionFcnPtr;
|
|
|
|
|
|
|
|
typedef CUresult CUDAAPI CuDeviceComputeCapabilityFcnTy(int *, int *, CUdevice);
|
|
|
|
static CuDeviceComputeCapabilityFcnTy *CuDeviceComputeCapabilityFcnPtr;
|
|
|
|
|
|
|
|
typedef CUresult CUDAAPI CuDeviceGetNameFcnTy(char *, int, CUdevice);
|
|
|
|
static CuDeviceGetNameFcnTy *CuDeviceGetNameFcnPtr;
|
|
|
|
|
|
|
|
/* Type-defines of function pointer ot CUDA runtime APIs. */
|
|
|
|
typedef cudaError_t CUDARTAPI CudaThreadSynchronizeFcnTy(void);
|
|
|
|
static CudaThreadSynchronizeFcnTy *CudaThreadSynchronizeFcnPtr;
|
|
|
|
|
|
|
|
static void *getAPIHandle(void *Handle, const char *FuncName) {
|
|
|
|
char *Err;
|
|
|
|
void *FuncPtr;
|
|
|
|
dlerror();
|
|
|
|
FuncPtr = dlsym(Handle, FuncName);
|
|
|
|
if ((Err = dlerror()) != 0) {
|
|
|
|
fprintf(stdout, "Load CUDA driver API failed: %s. \n", Err);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return FuncPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int initialDeviceAPILibraries() {
|
|
|
|
HandleCuda = dlopen("libcuda.so", RTLD_LAZY);
|
|
|
|
if (!HandleCuda) {
|
|
|
|
printf("Cannot open library: %s. \n", dlerror());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
HandleCudaRT = dlopen("libcudart.so", RTLD_LAZY);
|
|
|
|
if (!HandleCudaRT) {
|
|
|
|
printf("Cannot open library: %s. \n", dlerror());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int initialDeviceAPIs() {
|
|
|
|
if (initialDeviceAPILibraries() == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Get function pointer to CUDA Driver APIs.
|
|
|
|
*
|
|
|
|
* Note that compilers conforming to the ISO C standard are required to
|
|
|
|
* generate a warning if a conversion from a void * pointer to a function
|
|
|
|
* pointer is attempted as in the following statements. The warning
|
|
|
|
* of this kind of cast may not be emitted by clang and new versions of gcc
|
|
|
|
* as it is valid on POSIX 2008.
|
|
|
|
*/
|
2013-03-23 09:05:07 +08:00
|
|
|
CuFuncSetBlockShapeFcnPtr = (CuFuncSetBlockShapeFcnTy *)getAPIHandle(
|
|
|
|
HandleCuda, "cuFuncSetBlockShape");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
CuParamSetvFcnPtr =
|
|
|
|
(CuParamSetvFcnTy *)getAPIHandle(HandleCuda, "cuParamSetv");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
CuParamSetSizeFcnPtr =
|
|
|
|
(CuParamSetSizeFcnTy *)getAPIHandle(HandleCuda, "cuParamSetSize");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
CuLaunchGridFcnPtr =
|
|
|
|
(CuLaunchGridFcnTy *)getAPIHandle(HandleCuda, "cuLaunchGrid");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
CuMemAllocFcnPtr =
|
|
|
|
(CuMemAllocFcnTy *)getAPIHandle(HandleCuda, "cuMemAlloc_v2");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
CuMemFreeFcnPtr = (CuMemFreeFcnTy *)getAPIHandle(HandleCuda, "cuMemFree_v2");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
CuMemcpyDtoHFcnPtr =
|
|
|
|
(CuMemcpyDtoHFcnTy *)getAPIHandle(HandleCuda, "cuMemcpyDtoH_v2");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
CuMemcpyHtoDFcnPtr =
|
|
|
|
(CuMemcpyHtoDFcnTy *)getAPIHandle(HandleCuda, "cuMemcpyHtoD_v2");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
CuModuleUnloadFcnPtr =
|
|
|
|
(CuModuleUnloadFcnTy *)getAPIHandle(HandleCuda, "cuModuleUnload");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
CuCtxDestroyFcnPtr =
|
|
|
|
(CuCtxDestroyFcnTy *)getAPIHandle(HandleCuda, "cuCtxDestroy");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
CuInitFcnPtr = (CuInitFcnTy *)getAPIHandle(HandleCuda, "cuInit");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
CuDeviceGetCountFcnPtr =
|
|
|
|
(CuDeviceGetCountFcnTy *)getAPIHandle(HandleCuda, "cuDeviceGetCount");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
CuDeviceGetFcnPtr =
|
|
|
|
(CuDeviceGetFcnTy *)getAPIHandle(HandleCuda, "cuDeviceGet");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
CuCtxCreateFcnPtr =
|
|
|
|
(CuCtxCreateFcnTy *)getAPIHandle(HandleCuda, "cuCtxCreate_v2");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
|
|
|
CuModuleLoadDataExFcnPtr =
|
2013-03-23 09:05:07 +08:00
|
|
|
(CuModuleLoadDataExFcnTy *)getAPIHandle(HandleCuda, "cuModuleLoadDataEx");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
CuModuleGetFunctionFcnPtr = (CuModuleGetFunctionFcnTy *)getAPIHandle(
|
|
|
|
HandleCuda, "cuModuleGetFunction");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
|
|
|
CuDeviceComputeCapabilityFcnPtr =
|
2013-03-23 09:05:07 +08:00
|
|
|
(CuDeviceComputeCapabilityFcnTy *)getAPIHandle(
|
|
|
|
HandleCuda, "cuDeviceComputeCapability");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
|
|
|
CuDeviceGetNameFcnPtr =
|
2013-03-23 09:05:07 +08:00
|
|
|
(CuDeviceGetNameFcnTy *)getAPIHandle(HandleCuda, "cuDeviceGetName");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
|
|
|
/* Get function pointer to CUDA Runtime APIs. */
|
2013-03-23 09:05:07 +08:00
|
|
|
CudaThreadSynchronizeFcnPtr = (CudaThreadSynchronizeFcnTy *)getAPIHandle(
|
|
|
|
HandleCudaRT, "cudaThreadSynchronize");
|
2012-06-11 17:25:01 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-07-25 17:16:01 +08:00
|
|
|
PollyGPUContext *polly_initContext() {
|
2016-07-25 17:15:53 +08:00
|
|
|
DebugMode = getenv("POLLY_DEBUG") != 0;
|
|
|
|
|
2016-07-06 11:04:47 +08:00
|
|
|
dump_function();
|
2016-07-25 17:16:01 +08:00
|
|
|
PollyGPUContext *Context;
|
|
|
|
CUdevice Device;
|
2016-07-06 11:04:47 +08:00
|
|
|
|
2012-06-11 17:25:01 +08:00
|
|
|
int Major = 0, Minor = 0, DeviceID = 0;
|
|
|
|
char DeviceName[256];
|
|
|
|
int DeviceCount = 0;
|
|
|
|
|
|
|
|
/* Get API handles. */
|
|
|
|
if (initialDeviceAPIs() == 0) {
|
|
|
|
fprintf(stdout, "Getting the \"handle\" for the CUDA driver API failed.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CuInitFcnPtr(0) != CUDA_SUCCESS) {
|
|
|
|
fprintf(stdout, "Initializing the CUDA driver API failed.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get number of devices that supports CUDA. */
|
|
|
|
CuDeviceGetCountFcnPtr(&DeviceCount);
|
|
|
|
if (DeviceCount == 0) {
|
|
|
|
fprintf(stdout, "There is no device supporting CUDA.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2016-07-25 17:16:01 +08:00
|
|
|
CuDeviceGetFcnPtr(&Device, 0);
|
2012-06-11 17:25:01 +08:00
|
|
|
|
|
|
|
/* Get compute capabilities and the device name. */
|
2016-07-25 17:16:01 +08:00
|
|
|
CuDeviceComputeCapabilityFcnPtr(&Major, &Minor, Device);
|
|
|
|
CuDeviceGetNameFcnPtr(DeviceName, 256, Device);
|
2016-07-06 11:04:53 +08:00
|
|
|
debug_print("> Running on GPU device %d : %s.\n", DeviceID, DeviceName);
|
2012-06-11 17:25:01 +08:00
|
|
|
|
|
|
|
/* Create context on the device. */
|
2016-07-25 17:16:01 +08:00
|
|
|
Context = (PollyGPUContext *)malloc(sizeof(PollyGPUContext));
|
|
|
|
if (Context == 0) {
|
2012-07-05 05:45:03 +08:00
|
|
|
fprintf(stdout, "Allocate memory for Polly GPU context failed.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2016-07-25 17:16:01 +08:00
|
|
|
CuCtxCreateFcnPtr(&(Context->Cuda), 0, Device);
|
|
|
|
|
|
|
|
return Context;
|
2012-06-11 17:25:01 +08:00
|
|
|
}
|
|
|
|
|
2012-07-05 05:45:03 +08:00
|
|
|
void polly_getPTXModule(void *PTXBuffer, PollyGPUModule **Module) {
|
2016-07-06 11:04:47 +08:00
|
|
|
dump_function();
|
|
|
|
|
2012-07-05 05:45:03 +08:00
|
|
|
*Module = malloc(sizeof(PollyGPUModule));
|
|
|
|
if (*Module == 0) {
|
|
|
|
fprintf(stdout, "Allocate memory for Polly GPU module failed.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
if (CuModuleLoadDataExFcnPtr(&((*Module)->Cuda), PTXBuffer, 0, 0, 0) !=
|
2016-03-08 15:34:58 +08:00
|
|
|
CUDA_SUCCESS) {
|
2012-06-11 17:25:01 +08:00
|
|
|
fprintf(stdout, "Loading ptx assembly text failed.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-05 05:45:03 +08:00
|
|
|
void polly_getPTXKernelEntry(const char *KernelName, PollyGPUModule *Module,
|
|
|
|
PollyGPUFunction **Kernel) {
|
2016-07-06 11:04:47 +08:00
|
|
|
dump_function();
|
|
|
|
|
2012-07-05 05:45:03 +08:00
|
|
|
*Kernel = malloc(sizeof(PollyGPUFunction));
|
|
|
|
if (*Kernel == 0) {
|
|
|
|
fprintf(stdout, "Allocate memory for Polly GPU kernel failed.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2012-06-11 17:25:01 +08:00
|
|
|
/* Locate the kernel entry point. */
|
2013-03-23 09:05:07 +08:00
|
|
|
if (CuModuleGetFunctionFcnPtr(&((*Kernel)->Cuda), Module->Cuda, KernelName) !=
|
2016-03-08 15:34:58 +08:00
|
|
|
CUDA_SUCCESS) {
|
2012-06-11 17:25:01 +08:00
|
|
|
fprintf(stdout, "Loading kernel function failed.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-05 05:45:03 +08:00
|
|
|
void polly_copyFromHostToDevice(PollyGPUDevicePtr *DevData, void *HostData,
|
2012-06-11 17:25:01 +08:00
|
|
|
int MemSize) {
|
2016-07-06 11:04:47 +08:00
|
|
|
dump_function();
|
|
|
|
|
2012-07-05 05:45:03 +08:00
|
|
|
CUdeviceptr CuDevData = DevData->Cuda;
|
|
|
|
CuMemcpyHtoDFcnPtr(CuDevData, HostData, MemSize);
|
2012-06-11 17:25:01 +08:00
|
|
|
}
|
|
|
|
|
2012-07-05 05:45:03 +08:00
|
|
|
void polly_copyFromDeviceToHost(void *HostData, PollyGPUDevicePtr *DevData,
|
2012-06-11 17:25:01 +08:00
|
|
|
int MemSize) {
|
2016-07-06 11:04:47 +08:00
|
|
|
dump_function();
|
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
if (CuMemcpyDtoHFcnPtr(HostData, DevData->Cuda, MemSize) != CUDA_SUCCESS) {
|
2012-06-11 17:25:01 +08:00
|
|
|
fprintf(stdout, "Copying results from device to host memory failed.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-05 05:45:03 +08:00
|
|
|
void polly_setKernelParameters(PollyGPUFunction *Kernel, int BlockWidth,
|
|
|
|
int BlockHeight, PollyGPUDevicePtr *DevData) {
|
2016-07-06 11:04:47 +08:00
|
|
|
dump_function();
|
|
|
|
|
2012-06-11 17:25:01 +08:00
|
|
|
int ParamOffset = 0;
|
2012-07-05 05:45:03 +08:00
|
|
|
|
|
|
|
CuFuncSetBlockShapeFcnPtr(Kernel->Cuda, BlockWidth, BlockHeight, 1);
|
|
|
|
CuParamSetvFcnPtr(Kernel->Cuda, ParamOffset, &(DevData->Cuda),
|
|
|
|
sizeof(DevData->Cuda));
|
|
|
|
ParamOffset += sizeof(DevData->Cuda);
|
|
|
|
CuParamSetSizeFcnPtr(Kernel->Cuda, ParamOffset);
|
2012-06-11 17:25:01 +08:00
|
|
|
}
|
|
|
|
|
2012-07-05 05:45:03 +08:00
|
|
|
void polly_launchKernel(PollyGPUFunction *Kernel, int GridWidth,
|
|
|
|
int GridHeight) {
|
2016-07-06 11:04:47 +08:00
|
|
|
dump_function();
|
|
|
|
|
2012-07-05 05:45:03 +08:00
|
|
|
if (CuLaunchGridFcnPtr(Kernel->Cuda, GridWidth, GridHeight) != CUDA_SUCCESS) {
|
2012-06-11 17:25:01 +08:00
|
|
|
fprintf(stdout, "Launching CUDA kernel failed.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
CudaThreadSynchronizeFcnPtr();
|
2016-07-06 11:04:53 +08:00
|
|
|
debug_print("CUDA kernel launched.\n");
|
2012-06-11 17:25:01 +08:00
|
|
|
}
|
|
|
|
|
2016-07-25 20:47:33 +08:00
|
|
|
void polly_freeDeviceMemory(PollyGPUDevicePtr *Allocation) {
|
|
|
|
dump_function();
|
|
|
|
CuMemFreeFcnPtr((CUdeviceptr)Allocation->Cuda);
|
|
|
|
free(Allocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
PollyGPUDevicePtr *polly_allocateMemoryForDevice(long MemSize) {
|
|
|
|
dump_function();
|
|
|
|
|
|
|
|
PollyGPUDevicePtr *DevData = malloc(sizeof(PollyGPUDevicePtr));
|
|
|
|
|
|
|
|
if (DevData == 0) {
|
|
|
|
fprintf(stdout, "Allocate memory for GPU device memory pointer failed.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
CUresult Res = CuMemAllocFcnPtr(&(DevData->Cuda), MemSize);
|
|
|
|
|
|
|
|
if (Res != CUDA_SUCCESS) {
|
|
|
|
fprintf(stdout, "Allocate memory for GPU device memory pointer failed.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return DevData;
|
|
|
|
}
|
|
|
|
|
2016-07-25 17:16:01 +08:00
|
|
|
void polly_freeContext(PollyGPUContext *Context) {
|
2016-07-25 20:47:28 +08:00
|
|
|
dump_function();
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2012-07-05 05:45:03 +08:00
|
|
|
if (Context->Cuda) {
|
|
|
|
CuCtxDestroyFcnPtr(Context->Cuda);
|
|
|
|
free(Context);
|
2012-06-11 17:25:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dlclose(HandleCuda);
|
|
|
|
dlclose(HandleCudaRT);
|
|
|
|
}
|