Bug Summary

File:OMCompiler/SimulationRuntime/ParModelica/explicit/openclrt/omc_ocl_memory_ops.cpp
Warning:line 136, column 5
Value stored to 'size' is never read

Annotated Source Code

[?] Use j/k keys for keyboard navigation

1/*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-CurrentYear, Linköping University,
5 * Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3
11 * AND THIS OSMC PUBLIC LICENSE (OSMC-PL).
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
13 * ACCEPTANCE OF THE OSMC PUBLIC LICENSE.
14 *
15 * The OpenModelica software and the Open Source Modelica
16 * Consortium (OSMC) Public License (OSMC-PL) are obtained
17 * from Linköping University, either from the above address,
18 * from the URLs: http://www.ida.liu.se/projects/OpenModelica or
19 * http://www.openmodelica.org, and in the OpenModelica distribution.
20 * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
21 *
22 * This program is distributed WITHOUT ANY WARRANTY; without
23 * even the implied warranty of MERCHANTABILITY or FITNESS
24 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
25 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
26 * OF OSMC-PL.
27 *
28 * See the full OSMC Public License conditions for more details.
29 *
30 */
31
32
33/*
34
35 This file contains functions for memory related operations.
36 Allocating, initializing, copying of memory on/from GPU/CPU
37 to GPU/CPU is handled by this functions.
38
39 See the header file for more comments.
40
41 Mahder.Gebremedhin@liu.se 2012-03-31
42
43*/
44
45
46
47#include <omc_ocl_memory_ops.h>
48
49
50
51cl_mem ocl_device_alloc(size_t size){
52
53 cl_int err;
54 cl_mem tmp = NULL__null;
55
56 if (!device_comm_queue)
57 ocl_initialize();
58
59 tmp = clCreateBuffer(device_context, CL_MEM_READ_WRITE(1 << 0),
60 size, NULL__null, &err);
61
62 ocl_error_check(OCL_CREATE_BUFFER, err);
63 return tmp;
64}
65
66cl_mem ocl_device_alloc_init(modelica_integer* host_array, size_t size){
67
68 cl_int err;
69 cl_mem tmp = NULL__null;
70
71 if (!device_comm_queue)
72 ocl_initialize();
73
74 if (host_array)
75 tmp = clCreateBuffer(device_context, CL_MEM_READ_WRITE(1 << 0) |
76 CL_MEM_COPY_HOST_PTR(1 << 5), size, host_array, &err);
77
78 ocl_error_check(OCL_CREATE_BUFFER, err);
79
80 return tmp;
81
82}
83
84cl_mem ocl_device_alloc_init(modelica_real* host_array, size_t size){
85
86 cl_int err;
87 cl_mem tmp = NULL__null;
88
89 if (!device_comm_queue)
90 ocl_initialize();
91
92 if (host_array)
93 tmp = clCreateBuffer(device_context, CL_MEM_READ_WRITE(1 << 0) |
94 CL_MEM_COPY_HOST_PTR(1 << 5), size, host_array, &err);
95
96 ocl_error_check(OCL_CREATE_BUFFER, err);
97
98 return tmp;
99
100}
101
102
103cl_mem ocl_alloc_init(void* src_data, size_t size){
104 cl_int err;
105 cl_mem tmp = NULL__null;
106
107 if (!device_comm_queue)
108 ocl_initialize();
109
110 if (src_data)
111 tmp = clCreateBuffer(device_context, CL_MEM_READ_WRITE(1 << 0) |
112 CL_MEM_COPY_HOST_PTR(1 << 5), size, src_data, &err);
113
114 else
115 tmp = clCreateBuffer(device_context, CL_MEM_READ_WRITE(1 << 0),
116 size, NULL__null, &err);
117
118 ocl_error_check(OCL_CREATE_BUFFER, err);
119
120 return tmp;
121
122}
123
124
125void ocl_create_execution_memory_buffer(device_buffer* d_buff){
126
127 cl_int err;
128 cl_ulong mem;
129 cl_ulong mem2;
130 cl_mem tmp;
131 cl_ulong size;
132
133 clGetDeviceInfo(ocl_device, CL_DEVICE_GLOBAL_MEM_SIZE0x101F, sizeof(cl_ulong), &mem, NULL__null);
134 clGetDeviceInfo(ocl_device, CL_DEVICE_MAX_MEM_ALLOC_SIZE0x1010, sizeof(cl_ulong), &mem2, NULL__null);
135 size = mem/OCL_BUFFER_SIZE_FRACTION4;
136 size = (size > mem2 ? mem2 : size);
Value stored to 'size' is never read
137 size = 30 * 1024 * 1024 * sizeof(modelica_integer);
138 //printf("Allocating : %llu MB for execution memory buffer \n", size/1024/1024);
139 tmp = clCreateBuffer(device_context, CL_MEM_READ_WRITE(1 << 0),
140 size, NULL__null, &err);
141
142 ocl_error_check(OCL_CREATE_BUFFER, err);
143 if(err){
144 printf("Error: Allocating execution memory buffer");
145 exit(1);
146 }
147
148 d_buff->buffer = tmp;
149 d_buff->size = size;
150}
151
152
153cl_mem ocl_alloc_init_real_arr(modelica_real* host_array, int a_size){
154 cl_int err;
155 cl_mem tmp;
156 if (!device_comm_queue)
157 ocl_initialize();
158
159 if (host_array)
160 tmp = clCreateBuffer(device_context, CL_MEM_READ_WRITE(1 << 0) |
161 CL_MEM_COPY_HOST_PTR(1 << 5), sizeof(modelica_real) * a_size, host_array, &err);
162
163 else
164 tmp = clCreateBuffer(device_context, CL_MEM_READ_WRITE(1 << 0),
165 sizeof(modelica_real) * a_size, NULL__null, &err);
166
167 ocl_error_check(OCL_CREATE_BUFFER, err);
168
169 return tmp;
170
171}
172
173cl_mem ocl_alloc_init_integer_arr(cl_int* host_array, int a_size){
174 cl_int err;
175 if (!device_comm_queue)
176 ocl_initialize();
177
178 if (host_array)
179 return clCreateBuffer(device_context, CL_MEM_READ_WRITE(1 << 0) |
180 CL_MEM_COPY_HOST_PTR(1 << 5), sizeof(modelica_integer) * a_size, host_array, &err);
181
182 else
183 return clCreateBuffer(device_context, CL_MEM_READ_WRITE(1 << 0),
184 sizeof(modelica_integer) * a_size, NULL__null, &err);
185
186 ocl_error_check(OCL_CREATE_BUFFER, err);
187
188}
189
190
191
192
193void ocl_copy_to_device_real(cl_mem dev_dest_array, modelica_real* src_host_array, int a_size){
194 cl_int err;
195 if (!device_comm_queue)
196 printf("ERROR: ocl_copy_to_device_real(): tryig to copy to device with no command queue created: not initialized OCL env?");
197
198 err = clEnqueueWriteBuffer(device_comm_queue, dev_dest_array, CL_TRUE1, 0,
199 a_size * sizeof(modelica_real), src_host_array, 0, NULL__null, NULL__null);
200
201 ocl_error_check(OCL_COPY_HOST_TO_DEV, err);
202}
203
204void ocl_copy_device_to_device_real(cl_mem dev_src_array, cl_mem device_dest_array, int a_size){
205 cl_int err;
206 if (!device_comm_queue)
207 printf("ERROR: ocl_copy_device_to_device_real(): tryig to copy device to device with no command queue created: not initialized OCL env?");
208
209 err = clEnqueueCopyBuffer(device_comm_queue, dev_src_array, device_dest_array, 0, 0,
210 a_size * sizeof(modelica_real), 0, NULL__null, NULL__null);
211
212 ocl_error_check(OCL_COPY_DEV_TO_DEV, err);
213}
214
215void ocl_copy_back_to_host_real(cl_mem dev_output_array, modelica_real* dest_host_array, int a_size){
216 cl_int err;
217 if (!device_comm_queue)
218 printf("ERROR: ocl_copy_back_to_host_real(): tryig to copy back non existent data");
219
220 err = clEnqueueReadBuffer(device_comm_queue, dev_output_array, CL_TRUE1, 0,
221 a_size * sizeof(modelica_real), dest_host_array, 0, NULL__null, NULL__null);
222
223 ocl_error_check(OCL_COPY_DEV_TO_HOST, err);
224}
225
226void ocl_copy_to_device_integer(cl_mem dev_dest_array, modelica_integer* src_host_array, int a_size){
227 cl_int err;
228 if (!device_comm_queue)
229 printf("ERROR: ocl_copy_to_device_integer(): tryig to copy to device with no command queue created: not initialized OCL env?");
230
231 err = clEnqueueWriteBuffer(device_comm_queue, dev_dest_array, CL_TRUE1, 0,
232 a_size * sizeof(modelica_integer), src_host_array, 0, NULL__null, NULL__null);
233
234 ocl_error_check(OCL_COPY_HOST_TO_DEV, err);
235}
236
237void ocl_copy_device_to_device_integer(cl_mem dev_src_array, cl_mem device_dest_array, int a_size){
238 cl_int err;
239 if (!device_comm_queue)
240 printf("ERROR: ocl_copy_device_to_device_integer(): tryig to copy device to device with no command queue created: not initialized OCL env?");
241
242 err = clEnqueueCopyBuffer(device_comm_queue, dev_src_array, device_dest_array, 0, 0,
243 a_size * sizeof(modelica_integer), 0, NULL__null, NULL__null);
244
245 ocl_error_check(OCL_COPY_DEV_TO_DEV, err);
246}
247
248
249void ocl_copy_back_to_host_integer(cl_mem dev_output_array, modelica_integer* dest_host_array, int a_size){
250 cl_int err;
251 if (!device_comm_queue)
252 printf("ERROR: ocl_copy_back_to_host_int(): tryig to copy back non existent data");
253
254 err = clEnqueueReadBuffer(device_comm_queue, dev_output_array, CL_TRUE1, 0,
255 a_size * sizeof(modelica_integer), dest_host_array, 0, NULL__null, NULL__null);
256
257 ocl_error_check(OCL_COPY_DEV_TO_HOST, err);
258}
259