Mercurial > hg > truffle
annotate src/gpu/ptx/vm/gpu_ptx.hpp @ 11842:8d8f63069f58
PTX warp limiter to available GPU processors
author | Morris Meyer <morris.meyer@oracle.com> |
---|---|
date | Mon, 30 Sep 2013 13:03:47 -0400 |
parents | 365d8f385fb5 |
children | c7abc8411011 |
rev | line source |
---|---|
10879 | 1 /* |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 * | |
23 */ | |
24 | |
25 #ifndef GPU_PTX_HPP | |
26 #define GPU_PTX_HPP | |
27 | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
28 /* |
10879 | 29 * Some useful macro definitions from publicly available cuda.h. |
30 * These definitions are for convenience. | |
31 */ | |
32 #define GRAAL_CUDA_SUCCESS 0 | |
11283
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
33 /**< Device shares a unified address space with the host */ |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
34 #define GRAAL_CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING 41 |
10879 | 35 #define GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR 75 |
36 #define GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR 76 | |
11842
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
37 #define GRAAL_CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT 16 |
10879 | 38 #define GRAAL_CU_JIT_MAX_REGISTERS 0 |
39 #define GRAAL_CU_JIT_THREADS_PER_BLOCK 1 | |
40 #define GRAAL_CU_JIT_INFO_LOG_BUFFER 3 | |
41 #define GRAAL_CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES 4 | |
42 #define GRAAL_CUDA_ERROR_NO_BINARY_FOR_GPU 209 | |
43 | |
11283
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
44 /** |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
45 * End of array terminator for the extra parameter to |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
46 * ::cuLaunchKernel |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
47 */ |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
48 #define GRAAL_CU_LAUNCH_PARAM_END ((void*) 0x00) |
11283
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
49 |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
50 /** |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
51 * Indicator that the next value in the extra parameter to |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
52 * ::cuLaunchKernel will be a pointer to a buffer containing all kernel |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
53 * parameters used for launching kernel f. This buffer needs to |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
54 * honor all alignment/padding requirements of the individual parameters. |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
55 * If ::GRAAL_CU_LAUNCH_PARAM_BUFFER_SIZE is not also specified in the |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
56 * extra array, then ::GRAAL_CU_LAUNCH_PARAM_BUFFER_POINTER will have no |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
57 * effect. |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
58 */ |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
59 #define GRAAL_CU_LAUNCH_PARAM_BUFFER_POINTER ((void*) 0x01) |
11283
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
60 |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
61 /** |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
62 * Indicator that the next value in the extra parameter to |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
63 * ::cuLaunchKernel will be a pointer to a size_t which contains the |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
64 * size of the buffer specified with ::GRAAL_CU_LAUNCH_PARAM_BUFFER_POINTER. |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
65 * It is required that ::GRAAL_CU_LAUNCH_PARAM_BUFFER_POINTER also be specified |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
66 * in the extra array if the value associated with |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
67 * ::GRAAL_CU_LAUNCH_PARAM_BUFFER_SIZE is not zero. |
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
68 */ |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
69 #define GRAAL_CU_LAUNCH_PARAM_BUFFER_SIZE ((void*) 0x02) |
11283
1cd1f8ff70a1
CR-20: PTX kernel invocation with arguments - from Bharadwaj
Morris Meyer <morris.meyer@oracle.com>
parents:
10879
diff
changeset
|
70 |
10879 | 71 class Ptx { |
72 friend class gpu; | |
73 | |
74 protected: | |
75 static bool probe_linkage(); | |
76 static bool initialize_gpu(); | |
11842
8d8f63069f58
PTX warp limiter to available GPU processors
Morris Meyer <morris.meyer@oracle.com>
parents:
11822
diff
changeset
|
77 static unsigned int total_cores(); |
10879 | 78 static void * generate_kernel(unsigned char *code, int code_len, const char *name); |
11822
365d8f385fb5
PTX: one-dimensional parallel warp invocation, ParallelOver annotation
Morris Meyer <morris.meyer@oracle.com>
parents:
11527
diff
changeset
|
79 static bool execute_warp(int dimX, int dimY, int dimZ, address kernel, PTXKernelArguments & ka, JavaValue &ret); |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
80 static bool execute_kernel(address kernel, PTXKernelArguments & ka, JavaValue &ret); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
81 public: |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
82 #if defined(__x86_64) || defined(AMD64) || defined(_M_AMD64) |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
83 typedef unsigned long long CUdeviceptr; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
84 #else |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
85 typedef unsigned int CUdeviceptr; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
86 #endif |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
87 |
10879 | 88 private: |
89 typedef int (*cuda_cu_init_func_t)(unsigned int); | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
90 typedef int (*cuda_cu_ctx_create_func_t)(void*, int, int); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
91 typedef int (*cuda_cu_ctx_destroy_func_t)(void*); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
92 typedef int (*cuda_cu_ctx_synchronize_func_t)(void); |
11527
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
93 typedef int (*cuda_cu_ctx_set_current_func_t)(void*); |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
94 typedef int (*cuda_cu_device_get_count_func_t)(int*); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
95 typedef int (*cuda_cu_device_get_name_func_t)(char*, int, int); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
96 typedef int (*cuda_cu_device_get_func_t)(int*, int); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
97 typedef int (*cuda_cu_device_compute_capability_func_t)(int*, int*, int); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
98 typedef int (*cuda_cu_device_get_attribute_func_t)(int*, int, int); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
99 typedef int (*cuda_cu_launch_kernel_func_t)(struct CUfunc_st*, |
10879 | 100 unsigned int, unsigned int, unsigned int, |
101 unsigned int, unsigned int, unsigned int, | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
102 unsigned int, void*, void**, void**); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
103 typedef int (*cuda_cu_module_get_function_func_t)(void*, void*, const char*); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
104 typedef int (*cuda_cu_module_load_data_ex_func_t)(void*, void*, unsigned int, void*, void**); |
11527
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
105 typedef int (*cuda_cu_memalloc_func_t)(void*, size_t); |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
106 typedef int (*cuda_cu_memfree_func_t)(gpu::Ptx::CUdeviceptr); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
107 typedef int (*cuda_cu_memcpy_htod_func_t)(gpu::Ptx::CUdeviceptr, const void*, unsigned int); |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
108 typedef int (*cuda_cu_memcpy_dtoh_func_t)(const void*, gpu::Ptx::CUdeviceptr, unsigned int); |
10879 | 109 |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
110 public: |
10879 | 111 static cuda_cu_init_func_t _cuda_cu_init; |
112 static cuda_cu_ctx_create_func_t _cuda_cu_ctx_create; | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
113 static cuda_cu_ctx_destroy_func_t _cuda_cu_ctx_destroy; |
10879 | 114 static cuda_cu_ctx_synchronize_func_t _cuda_cu_ctx_synchronize; |
115 static cuda_cu_device_get_count_func_t _cuda_cu_device_get_count; | |
116 static cuda_cu_device_get_name_func_t _cuda_cu_device_get_name; | |
117 static cuda_cu_device_get_func_t _cuda_cu_device_get; | |
118 static cuda_cu_device_compute_capability_func_t _cuda_cu_device_compute_capability; /* Deprecated as of CUDA 5.0 */ | |
119 static cuda_cu_device_get_attribute_func_t _cuda_cu_device_get_attribute; | |
120 static cuda_cu_launch_kernel_func_t _cuda_cu_launch_kernel; | |
121 static cuda_cu_module_get_function_func_t _cuda_cu_module_get_function; | |
122 static cuda_cu_module_load_data_ex_func_t _cuda_cu_module_load_data_ex; | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
123 static cuda_cu_memalloc_func_t _cuda_cu_memalloc; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
124 static cuda_cu_memfree_func_t _cuda_cu_memfree; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
125 static cuda_cu_memcpy_htod_func_t _cuda_cu_memcpy_htod; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
126 static cuda_cu_memcpy_dtoh_func_t _cuda_cu_memcpy_dtoh; |
11527
c99e65785936
Improvements to PTX codegen; allows more PTX tests that run on the device to pass.
bharadwaj
parents:
11485
diff
changeset
|
127 static cuda_cu_ctx_set_current_func_t _cuda_cu_ctx_set_current; |
10879 | 128 |
129 protected: | |
11485
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
130 static void* _device_context; |
49bb1bc983c6
Implement several missing PTX codegen features; return value capture and method args passing of java method executed on GPU.
bharadwaj
parents:
11291
diff
changeset
|
131 static int _cu_device; |
10879 | 132 }; |
133 #endif // GPU_PTX_HPP |