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 */
|
|
|
|
/* Open Source License. See LICENSE.TXT for details. */
|
2012-06-11 17:25:01 +08:00
|
|
|
/* */
|
|
|
|
/******************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* This file defines GPUJIT. */
|
|
|
|
/* */
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef GPUJIT_H_
|
|
|
|
#define GPUJIT_H_
|
|
|
|
|
2012-07-05 05:45:03 +08:00
|
|
|
/*
|
|
|
|
* The following demostrates how we can use the GPURuntime library to
|
|
|
|
* execute a GPU kernel.
|
|
|
|
*
|
|
|
|
* char KernelString[] = "\n\
|
|
|
|
* .version 1.4\n\
|
|
|
|
* .target sm_10, map_f64_to_f32\n\
|
|
|
|
* .entry _Z8myKernelPi (\n\
|
|
|
|
* .param .u64 __cudaparm__Z8myKernelPi_data)\n\
|
|
|
|
* {\n\
|
|
|
|
* .reg .u16 %rh<4>;\n\
|
|
|
|
* .reg .u32 %r<5>;\n\
|
|
|
|
* .reg .u64 %rd<6>;\n\
|
|
|
|
* cvt.u32.u16 %r1, %tid.x;\n\
|
|
|
|
* mov.u16 %rh1, %ctaid.x;\n\
|
|
|
|
* mov.u16 %rh2, %ntid.x;\n\
|
|
|
|
* mul.wide.u16 %r2, %rh1, %rh2;\n\
|
|
|
|
* add.u32 %r3, %r1, %r2;\n\
|
|
|
|
* ld.param.u64 %rd1, [__cudaparm__Z8myKernelPi_data];\n\
|
|
|
|
* cvt.s64.s32 %rd2, %r3;\n\
|
|
|
|
* mul.wide.s32 %rd3, %r3, 4;\n\
|
|
|
|
* add.u64 %rd4, %rd1, %rd3;\n\
|
|
|
|
* st.global.s32 [%rd4+0], %r3;\n\
|
|
|
|
* exit;\n\
|
|
|
|
* }\n\
|
|
|
|
* ";
|
|
|
|
*
|
|
|
|
* const char *Entry = "_Z8myKernelPi";
|
|
|
|
*
|
|
|
|
* int main() {
|
|
|
|
* PollyGPUFunction *Kernel;
|
2016-07-25 17:16:01 +08:00
|
|
|
* PollyGPUContext *Context;
|
2016-07-25 20:47:33 +08:00
|
|
|
* PollyGPUDevicePtr *DevArray;
|
2012-07-05 05:45:03 +08:00
|
|
|
* int *HostData;
|
|
|
|
* int MemSize;
|
2016-07-27 21:20:16 +08:00
|
|
|
*
|
|
|
|
* int GridX = 8;
|
|
|
|
* int GridY = 8;
|
|
|
|
*
|
|
|
|
* int BlockX = 16;
|
|
|
|
* int BlockY = 16;
|
|
|
|
* int BlockZ = 1;
|
2012-07-05 05:45:03 +08:00
|
|
|
*
|
|
|
|
* MemSize = 256*64*sizeof(int);
|
2016-07-25 17:16:01 +08:00
|
|
|
* Context = polly_initContext();
|
2016-07-25 20:47:33 +08:00
|
|
|
* DevArray = polly_allocateMemoryForDevice(MemSize);
|
2016-07-26 00:31:21 +08:00
|
|
|
* Kernel = polly_getKernel(KernelString, KernelName);
|
2016-07-27 21:20:16 +08:00
|
|
|
*
|
|
|
|
* void *Params[1];
|
|
|
|
* void *DevPtr = polly_getDevicePtr(DevArray)
|
|
|
|
* Params[0] = &DevPtr;
|
|
|
|
*
|
|
|
|
* polly_launchKernel(Kernel, GridX, GridY, BlockX, BlockY, BlockZ, Params);
|
|
|
|
*
|
2012-07-05 05:45:03 +08:00
|
|
|
* polly_copyFromDeviceToHost(HostData, DevData, MemSize);
|
2016-07-26 00:31:21 +08:00
|
|
|
* polly_freeKernel(Kernel);
|
2016-07-25 20:47:33 +08:00
|
|
|
* polly_freeDeviceMemory(DevArray);
|
2016-07-25 17:16:01 +08:00
|
|
|
* polly_freeContext(Context);
|
2012-07-05 05:45:03 +08:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
*/
|
2012-06-11 17:25:01 +08:00
|
|
|
|
2012-07-05 05:45:03 +08:00
|
|
|
typedef struct PollyGPUContextT PollyGPUContext;
|
|
|
|
typedef struct PollyGPUFunctionT PollyGPUFunction;
|
|
|
|
typedef struct PollyGPUDevicePtrT PollyGPUDevicePtr;
|
|
|
|
|
2016-07-25 17:16:01 +08:00
|
|
|
PollyGPUContext *polly_initContext();
|
2016-07-26 00:31:21 +08:00
|
|
|
PollyGPUFunction *polly_getKernel(const char *PTXBuffer,
|
|
|
|
const char *KernelName);
|
|
|
|
void polly_freeKernel(PollyGPUFunction *Kernel);
|
2016-07-25 20:47:39 +08:00
|
|
|
void polly_copyFromHostToDevice(void *HostData, PollyGPUDevicePtr *DevData,
|
|
|
|
long MemSize);
|
|
|
|
void polly_copyFromDeviceToHost(PollyGPUDevicePtr *DevData, void *HostData,
|
|
|
|
long MemSize);
|
2016-07-27 21:20:16 +08:00
|
|
|
void polly_launchKernel(PollyGPUFunction *Kernel, unsigned int GridDimX,
|
|
|
|
unsigned int GridDimY, unsigned int BlockSizeX,
|
|
|
|
unsigned int BlockSizeY, unsigned int BlockSizeZ,
|
|
|
|
void **Parameters);
|
2016-07-25 20:47:33 +08:00
|
|
|
void polly_freeDeviceMemory(PollyGPUDevicePtr *Allocation);
|
2016-07-25 20:47:25 +08:00
|
|
|
void polly_freeContext(PollyGPUContext *Context);
|
2012-06-11 17:25:01 +08:00
|
|
|
#endif /* GPUJIT_H_ */
|