comparison src/gpu/ptx/vm/gpu_ptx.cpp @ 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 372bacc13022
comparison
equal deleted inserted replaced
11841:6157a71e0a36 11842:8d8f63069f58
48 gpu::Ptx::cuda_cu_module_get_function_func_t gpu::Ptx::_cuda_cu_module_get_function; 48 gpu::Ptx::cuda_cu_module_get_function_func_t gpu::Ptx::_cuda_cu_module_get_function;
49 gpu::Ptx::cuda_cu_module_load_data_ex_func_t gpu::Ptx::_cuda_cu_module_load_data_ex; 49 gpu::Ptx::cuda_cu_module_load_data_ex_func_t gpu::Ptx::_cuda_cu_module_load_data_ex;
50 gpu::Ptx::cuda_cu_memcpy_dtoh_func_t gpu::Ptx::_cuda_cu_memcpy_dtoh; 50 gpu::Ptx::cuda_cu_memcpy_dtoh_func_t gpu::Ptx::_cuda_cu_memcpy_dtoh;
51 gpu::Ptx::cuda_cu_memfree_func_t gpu::Ptx::_cuda_cu_memfree; 51 gpu::Ptx::cuda_cu_memfree_func_t gpu::Ptx::_cuda_cu_memfree;
52 52
53
54 /*
55 * see http://en.wikipedia.org/wiki/CUDA#Supported_GPUs
56 */
57 int ncores(int major, int minor) {
58 int device_type = major << 4 + minor;
59
60 switch (device_type) {
61 case 0x10: return 8;
62 case 0x11: return 8;
63 case 0x12: return 8;
64 case 0x13: return 8;
65 case 0x20: return 32;
66 case 0x21: return 48;
67 case 0x30: return 192;
68 case 0x35: return 192;
69 defaulf:
70 tty->print_cr("[CUDA] Warning: Unhandled device %x", device_type);
71 return 0;
72 }
73 }
74
53 bool gpu::Ptx::initialize_gpu() { 75 bool gpu::Ptx::initialize_gpu() {
54 76
55 /* Initialize CUDA driver API */ 77 /* Initialize CUDA driver API */
56 int status = _cuda_cu_init(0); 78 int status = _cuda_cu_init(0);
57 if (status != GRAAL_CUDA_SUCCESS) { 79 if (status != GRAAL_CUDA_SUCCESS) {
93 if (TraceGPUInteraction) { 115 if (TraceGPUInteraction) {
94 tty->print_cr("[CUDA] Got the handle of first compute-device"); 116 tty->print_cr("[CUDA] Got the handle of first compute-device");
95 } 117 }
96 118
97 /* Get device attributes */ 119 /* Get device attributes */
98 int minor, major, unified_addressing; 120 int unified_addressing;
99 status = _cuda_cu_device_get_attribute(&minor, GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, _cu_device);
100
101 if (status != GRAAL_CUDA_SUCCESS) {
102 tty->print_cr("[CUDA] Failed to get minor attribute of device: %d", _cu_device);
103 return false;
104 }
105
106 status = _cuda_cu_device_get_attribute(&major, GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, _cu_device);
107
108 if (status != GRAAL_CUDA_SUCCESS) {
109 tty->print_cr("[CUDA] Failed to get major attribute of device: %d", _cu_device);
110 return false;
111 }
112
113 if (TraceGPUInteraction) {
114 tty->print_cr("[CUDA] Compatibility version of device %d: %d.%d", _cu_device, major, minor);
115 }
116 121
117 status = _cuda_cu_device_get_attribute(&unified_addressing, GRAAL_CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING, _cu_device); 122 status = _cuda_cu_device_get_attribute(&unified_addressing, GRAAL_CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING, _cu_device);
118 123
119 if (status != GRAAL_CUDA_SUCCESS) { 124 if (status != GRAAL_CUDA_SUCCESS) {
120 tty->print_cr("[CUDA] Failed to query unified addressing mode of device: %d", _cu_device); 125 tty->print_cr("[CUDA] Failed to query unified addressing mode of device: %d", _cu_device);
137 142
138 if (TraceGPUInteraction) { 143 if (TraceGPUInteraction) {
139 tty->print_cr("[CUDA] Using %s", device_name); 144 tty->print_cr("[CUDA] Using %s", device_name);
140 } 145 }
141 146
147
142 return true; 148 return true;
149 }
150
151 unsigned int gpu::Ptx::total_cores() {
152
153 int minor, major, nmp;
154 int status = _cuda_cu_device_get_attribute(&minor,
155 GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR,
156 _cu_device);
157
158 if (status != GRAAL_CUDA_SUCCESS) {
159 tty->print_cr("[CUDA] Failed to get minor attribute of device: %d", _cu_device);
160 return 0;
161 }
162
163 status = _cuda_cu_device_get_attribute(&major,
164 GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR,
165 _cu_device);
166
167 if (status != GRAAL_CUDA_SUCCESS) {
168 tty->print_cr("[CUDA] Failed to get major attribute of device: %d", _cu_device);
169 return 0;
170 }
171
172 status = _cuda_cu_device_get_attribute(&nmp,
173 GRAAL_CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT,
174 _cu_device);
175
176 if (status != GRAAL_CUDA_SUCCESS) {
177 tty->print_cr("[CUDA] Failed to get numberof MPs on device: %d", _cu_device);
178 return 0;
179 }
180
181 int total = nmp * ncores(major, minor);
182
183 if (TraceGPUInteraction) {
184 tty->print_cr("[CUDA] Compatibility version of device %d: %d.%d", _cu_device, major, minor);
185 tty->print_cr("[CUDA] Number of cores: %d", total);
186 }
187 return (total);
188
143 } 189 }
144 190
145 void *gpu::Ptx::generate_kernel(unsigned char *code, int code_len, const char *name) { 191 void *gpu::Ptx::generate_kernel(unsigned char *code, int code_len, const char *name) {
146 192
147 struct CUmod_st * cu_module; 193 struct CUmod_st * cu_module;