comparison src/gpu/ptx/vm/kernelArguments.cpp @ 11589:2afda67175e9

Merge
author Mick Jordan <mick.jordan@oracle.com>
date Tue, 03 Sep 2013 16:48:17 -0700
parents 49bb1bc983c6
children
comparison
equal deleted inserted replaced
11588:12f1d5fe0133 11589:2afda67175e9
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 #include "precompiled.hpp"
26 #include "kernelArguments.hpp"
27 #include "runtime/javaCalls.hpp"
28
29 gpu::Ptx::cuda_cu_memalloc_func_t gpu::Ptx::_cuda_cu_memalloc;
30 gpu::Ptx::cuda_cu_memcpy_htod_func_t gpu::Ptx::_cuda_cu_memcpy_htod;
31
32 // Get next java argument
33 oop PTXKernelArguments::next_arg(BasicType expectedType) {
34 assert(_index < _args->length(), "out of bounds");
35 oop arg=((objArrayOop) (_args))->obj_at(_index++);
36 assert(expectedType == T_OBJECT || java_lang_boxing_object::is_instance(arg, expectedType), "arg type mismatch");
37 return arg;
38 }
39
40 void PTXKernelArguments::do_int() {
41 // If the parameter is a return value,
42 if (is_return_type()) {
43 // Allocate device memory for T_INT return value pointer on device. Size in bytes
44 int status = gpu::Ptx::_cuda_cu_memalloc(&_return_value_ptr, T_INT_BYTE_SIZE);
45 if (status != GRAAL_CUDA_SUCCESS) {
46 tty->print_cr("[CUDA] *** Error (%d) Failed to allocate memory for return value pointer on device", status);
47 _success = false;
48 return;
49 }
50 // Push _return_value_ptr to _kernelBuffer
51 *((gpu::Ptx::CUdeviceptr*) &_kernelArgBuffer[_bufferOffset]) = _return_value_ptr;
52 _bufferOffset += sizeof(_return_value_ptr);
53 }
54 else {
55 // Get the next java argument and its value which should be a T_INT
56 oop arg = next_arg(T_INT);
57 // Copy the java argument value to kernelArgBuffer
58 jvalue intval;
59 if (java_lang_boxing_object::get_value(arg, &intval) != T_INT) {
60 tty->print_cr("[CUDA] *** Error: Unexpected argument type; expecting T_INT");
61 _success = false;
62 return;
63 }
64 *((gpu::Ptx::CUdeviceptr*) &_kernelArgBuffer[_bufferOffset]) = intval.i;
65 _bufferOffset += sizeof(intval.i);
66 }
67 return;
68 }
69
70 void PTXKernelArguments::do_long() {
71 // If the parameter is a return value,
72 if (is_return_type()) {
73 // Allocate device memory for T_LONG return value pointer on device. Size in bytes
74 int status = gpu::Ptx::_cuda_cu_memalloc(&_return_value_ptr, T_LONG_BYTE_SIZE);
75 if (status != GRAAL_CUDA_SUCCESS) {
76 tty->print_cr("[CUDA] *** Error (%d) Failed to allocate memory for return value pointer on device", status);
77 _success = false;
78 return;
79 }
80 // Push _return_value_ptr to _kernelBuffer
81 *((gpu::Ptx::CUdeviceptr*) &_kernelArgBuffer[_bufferOffset]) = _return_value_ptr;
82 _bufferOffset += sizeof(_return_value_ptr);
83 }
84 else {
85 // Get the next java argument and its value which should be a T_LONG
86 oop arg = next_arg(T_LONG);
87 // Copy the java argument value to kernelArgBuffer
88 jvalue val;
89 if (java_lang_boxing_object::get_value(arg, &val) != T_LONG) {
90 tty->print_cr("[CUDA] *** Error: Unexpected argument type; expecting T_LONG");
91 _success = false;
92 return;
93 }
94 *((gpu::Ptx::CUdeviceptr*) &_kernelArgBuffer[_bufferOffset]) = val.j;
95 _bufferOffset += sizeof(val.j);
96 }
97 return;
98 }
99
100 void PTXKernelArguments::do_byte() {
101 // If the parameter is a return value,
102 if (is_return_type()) {
103 // Allocate device memory for T_BYTE return value pointer on device. Size in bytes
104 int status = gpu::Ptx::_cuda_cu_memalloc(&_return_value_ptr, T_BYTE_SIZE);
105 if (status != GRAAL_CUDA_SUCCESS) {
106 tty->print_cr("[CUDA] *** Error (%d) Failed to allocate memory for return value pointer on device", status);
107 _success = false;
108 return;
109 }
110 // Push _return_value_ptr to _kernelBuffer
111 *((gpu::Ptx::CUdeviceptr*) &_kernelArgBuffer[_bufferOffset]) = _return_value_ptr;
112 _bufferOffset += sizeof(_return_value_ptr);
113 }
114 else {
115 // Get the next java argument and its value which should be a T_BYTE
116 oop arg = next_arg(T_BYTE);
117 // Copy the java argument value to kernelArgBuffer
118 jvalue val;
119 if (java_lang_boxing_object::get_value(arg, &val) != T_BYTE) {
120 tty->print_cr("[CUDA] *** Error: Unexpected argument type; expecting T_BYTE");
121 _success = false;
122 return;
123 }
124 *((gpu::Ptx::CUdeviceptr*) &_kernelArgBuffer[_bufferOffset]) = val.b;
125 _bufferOffset += sizeof(val.b);
126 }
127 return;
128 }
129
130 // TODO implement other do_*