本文整理匯總了Python中pyopencl.enqueue_copy方法的典型用法代碼示例。如果您正苦於以下問題:Python pyopencl.enqueue_copy方法的具體用法?Python pyopencl.enqueue_copy怎麽用?Python pyopencl.enqueue_copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyopencl
的用法示例。
在下文中一共展示了pyopencl.enqueue_copy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: memset
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def memset(self, buffer, value, size):
"""set the memory in allocation to the value in value
:param allocation: An OpenCL Buffer to fill
:type allocation: pyopencl.Buffer
:param value: The value to set the memory to
:type value: a single 32-bit int
:param size: The size of to the allocation unit in bytes
:type size: int
"""
if isinstance(buffer, cl.Buffer):
try:
cl.enqueue_fill_buffer(self.queue, buffer, numpy.uint32(value), 0, size)
except AttributeError:
src=numpy.zeros(size, dtype='uint8')+numpy.uint8(value)
cl.enqueue_copy(self.queue, buffer, src)
示例2: anneal
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def anneal(self, prog, queue, rand, solutions, costs):
prog.ocl_sa_populate_solutions(queue,
(self.num_of_solutions,),
(1,),
self.__np_iterations,
self.__np_temperature,
self.__np_terminate_temperature,
self.__np_alpha,
solutions,
rand,
self.__dev_cityxy,
costs).wait()
cl.enqueue_copy(queue, self.__np_solution, solutions).wait()
cl.enqueue_copy(queue, self.__np_costs, costs).wait()
self.plot_best_solution()
示例3: __update_fitness_index_pair
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def __update_fitness_index_pair(self):
cl.enqueue_copy(self.__queue, self.__fitnesses, self.__dev_fitnesses)
ori = []
fitness_sum = 0.0
for idx, fitness in enumerate(self.__fitnesses):
ori.append((idx, fitness))
fitness_sum += fitness
self.__avg = fitness_sum / len(self.__fitnesses)
assert len(self.__best_indices) == len(self.__best_fitnesses)
assert len(self.__worst_indices) == len(self.__worst_fitnesses)
size_of_indices = len(self.__best_indices)
ori.sort(key=lambda item : item[1], reverse=self.__opt_for_max=='max')
tops = ori[:size_of_indices]
bottoms = ori[len(ori)-size_of_indices:]
for idx in range(size_of_indices):
self.__best_indices[idx] = tops[idx][0]
self.__best_fitnesses[idx] = tops[idx][1]
self.__worst_indices[idx] = bottoms[idx][0]
self.__worst_fitnesses[idx] = bottoms[idx][1]
cl.enqueue_copy(self.__queue, self.__dev_best_indices, self.__best_indices)
cl.enqueue_copy(self.__queue, self.__dev_worst_indices, self.__worst_indices)
示例4: memcpy_dtoh
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def memcpy_dtoh(self, dest, src):
"""perform a device to host memory copy
:param dest: A numpy array in host memory to store the data
:type dest: numpy.ndarray
:param src: An OpenCL Buffer to copy data from
:type src: pyopencl.Buffer
"""
if isinstance(src, cl.Buffer):
cl.enqueue_copy(self.queue, dest, src)
示例5: memcpy_htod
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def memcpy_htod(self, dest, src):
"""perform a host to device memory copy
:param dest: An OpenCL Buffer to copy data from
:type dest: pyopencl.Buffer
:param src: A numpy array in host memory to store the data
:type src: numpy.ndarray
"""
if isinstance(dest, cl.Buffer):
cl.enqueue_copy(self.queue, dest, src)
示例6: reset_fifo_index
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def reset_fifo_index(self):
self.output_forward[:] = 0
event = pyopencl.enqueue_copy(self.queue, self.output_backward_cl, self.output_backward)
event.wait()
self.zi1[:] = 0
event = pyopencl.enqueue_copy(self.queue, self.zi1_cl, self.zi1)
event.wait()
self.zi2[:] = 0
event = pyopencl.enqueue_copy(self.queue, self.zi2_cl, self.zi2)
event.wait()
示例7: detect_local_peaks_before_peeling_loop
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def detect_local_peaks_before_peeling_loop(self):
if self._plot_debug:
print('detect_local_peaks_before_peeling_loop')
#~ self.global_size = (self.max_wg_size * n, )
#~ self.local_size = (self.max_wg_size,)
# reset mask_already_tested
#~ print('yep', self.mask_already_tested.size, self.mask_already_tested.shape)
#~ pyopencl.enqueue_fill_buffer(self.queue, self.mask_already_tested_cl, np.zeros(1, dtype='uint8'), 0, self.mask_already_tested.size)
#~ print('yop')
self.mask_already_tested[:] = 0
event = pyopencl.enqueue_copy(self.queue, self.mask_already_tested_cl, self.mask_already_tested)
#~ print('yop')
gsize = self.fifo_size - (2 * self.n_span)
if gsize > self.max_wg_size:
n = int(np.ceil(gsize / self.max_wg_size))
global_size = (self.max_wg_size * n, )
local_size = (self.max_wg_size,)
else:
global_size = (gsize, )
local_size = (gsize, )
#~ print('global_size', global_size, 'local_size', local_size)
#~ exit()
event = pyopencl.enqueue_nd_range_kernel(self.queue, self.kern_detect_local_peaks, global_size, local_size,)
#~ if self._plot_debug:
#~ pyopencl.enqueue_copy(self.queue, self.fifo_residuals, self.fifo_residuals_cl)
#~ pyopencl.enqueue_copy(self.queue, self.nb_pending_peaks, self.nb_pending_peaks_cl)
#~ pyopencl.enqueue_copy(self.queue, self.pending_peaks, self.pending_peaks_cl)
#~ fig, ax = plt.subplots()
#~ ax.plot(self.fifo_residuals)
#~ plt.show()
示例8: _plot_before_peeling_loop
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def _plot_before_peeling_loop(self):
pyopencl.enqueue_copy(self.queue, self.fifo_residuals, self.fifo_residuals_cl)
self._plot_sigs_before = self.fifo_residuals.copy()
pyopencl.enqueue_copy(self.queue, self.nb_pending_peaks, self.nb_pending_peaks_cl)
pyopencl.enqueue_copy(self.queue, self.pending_peaks, self.pending_peaks_cl)
pending_peaks = self.pending_peaks[:self.nb_pending_peaks[0]]
peak_inds = pending_peaks['peak_index']
chan_inds = pending_peaks['peak_chan']
print(pending_peaks)
fig, ax = plt.subplots()
plot_sigs = self.fifo_residuals.copy()
self._plot_sigs_before = plot_sigs
for c in range(self.nb_channel):
plot_sigs[:, c] += c*30
ax.plot(plot_sigs, color='k')
ax.axvline(self.fifo_size - self.n_right, color='r')
ax.axvline(-self.n_left, color='r')
ax.scatter(peak_inds, plot_sigs[peak_inds, chan_inds], color='r')
#~ plt.show()
示例9: _plot_after_inner_peeling_loop
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def _plot_after_inner_peeling_loop(self):
return
#~ pyopencl.enqueue_copy(self.queue, self.nb_pending_peaks, self.nb_pending_peaks_cl)
#~ pyopencl.enqueue_copy(self.queue, self.pending_peaks, self.pending_peaks_cl)
pyopencl.enqueue_copy(self.queue, self.fifo_residuals, self.fifo_residuals_cl)
#~ self._plot_sigs_before = plot_sigs
#~ chan_order = np.argsort(self.channel_distances[0, :])
fig, ax = plt.subplots()
plot_sigs = self._plot_sigs_before.copy()
for c in range(self.nb_channel):
plot_sigs[:, c] += c*30
ax.plot(plot_sigs, color='b')
plot_sigs = self.fifo_residuals.copy()
for c in range(self.nb_channel):
plot_sigs[:, c] += c*30
ax.plot(plot_sigs, color='k')
ax.axvline(self.fifo_size - self.n_right, color='r')
ax.axvline(-self.n_left, color='r')
#~ mask = self.peakdetector.get_mask_peaks_in_chunk(self.fifo_residuals)
#~ peak_inds, chan_inds= np.nonzero(mask)
#~ peak_inds += self.n_span
#~ ax.scatter(peak_inds, plot_sigs[peak_inds, chan_inds], color='r')
#~ ax.plot(self.fifo_residuals)
plt.show()
self._plot_sigs_before = self.fifo_residuals.copy()
示例10: process_data
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def process_data(self, pos, newbuf):
if newbuf.shape[0] <self.chunksize:
newbuf2 = np.zeros((self.chunksize, self.nb_channel), dtype=self.dtype)
newbuf2[-newbuf.shape[0]:, :] = newbuf
newbuf = newbuf2
if not newbuf.flags['C_CONTIGUOUS']:
newbuf = newbuf.copy()
pyopencl.enqueue_copy(self.queue, self.sigs_cl, newbuf)
event = self.kern_detect_peaks(self.queue, self.global_size, self.local_size,
self.sigs_cl, self.ring_sum_cl, self.peak_mask_cl)
event.wait()
#~ if pos-(newbuf.shape[0]+2*self.n_span)<0:
# the very first buffer is sacrified because of peak span
#~ return None, None
pyopencl.enqueue_copy(self.queue, self.peak_mask, self.peak_mask_cl)
time_ind_peaks, = np.nonzero(self.peak_mask)
if time_ind_peaks.size>0:
time_ind_peaks += pos - self.chunksize - self.n_span
chan_ind_peaks = None# not in this method
return time_ind_peaks, chan_ind_peaks, None
return None, None, None
示例11: get_mask_peaks_in_chunk
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def get_mask_peaks_in_chunk(self, fifo_residuals):
pyopencl.enqueue_copy(self.queue, self.fifo_sigs_cl, fifo_residuals)
#~ print(self.chunksize, self.max_wg_size)
event = self.kern_get_mask_spatiotemporal_peaks(self.queue, self.global_size, self.local_size,
self.fifo_sigs_cl, self.neighbours_cl, self.mask_peaks_cl)
event.wait()
pyopencl.enqueue_copy(self.queue, self.mask_peaks, self.mask_peaks_cl)
return self.mask_peaks
示例12: update_elites
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def update_elites(self, elites):
assert self.__is_elitism_mode, 'Elitism Mode is {}'.format(self.__is_elitism_mode)
assert len(elites) == self.__elitism_top
if not self.state_machine.is_running():
return
with self.__elite_lock:
elites_dna_data = []
elites_fitnesses = []
# Concatenate all elites' dna / fitness into a single continuous memory
# layout.
for idx, elite_info in enumerate(elites):
fitness, elite_dna, worker_id = elite_info
if idx == 0:
print('updating {}/{} elites ... fitness = {} from worker {}'.format(idx+1, len(elites), fitness, worker_id))
elites_dna_data.extend(elite_dna)
elites_fitnesses.append(fitness)
# Convert the continuous memory to a device compatible memory layout.
self.__updated_elites = numpy.asarray(elites_dna_data, dtype=numpy.int32)
self.__updated_elite_fitnesses = numpy.asarray(elites_fitnesses, dtype=numpy.float32)
# Transfer it into device meory.
cl.enqueue_copy(self.__queue, self.__dev_updated_elites, self.__updated_elites)
cl.enqueue_copy(self.__queue, self.__dev_updated_elite_fitnesses, self.__updated_elite_fitnesses)
self.__elites_updated = True
示例13: restore
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def restore(self, data, ctx, queue, population):
other_chromosomes = data['other_chromosomes']
ratios = data['ratios']
# prepare CL memory
mf = cl.mem_flags
self.__dev_ratios = cl.Buffer(ctx, mf.WRITE_ONLY, ratios.nbytes)
self.__dev_other_chromosomes = cl.Buffer(ctx, mf.READ_WRITE | mf.COPY_HOST_PTR,
hostbuf=other_chromosomes)
# Copy data from main memory to GPU memory
cl.enqueue_copy(queue, self.__dev_ratios, ratios)
cl.enqueue_copy(queue, self.__dev_other_chromosomes, other_chromosomes)
示例14: process_data
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def process_data(self, pos, data):
assert data.shape[0]==self.chunksize
if not data.flags['C_CONTIGUOUS'] or data.dtype!=self.output_dtype:
chunk = np.ascontiguousarray(data, dtype=self.output_dtype)
else:
chunk = data
#Online filtfilt
event = pyopencl.enqueue_copy(self.queue, self.input_cl, chunk)
event = self.kern_forward_backward_filter(self.queue, (self.nb_channel,), (self.nb_channel,),
self.input_cl, self.coefficients_cl, self.zi1_cl, self.zi2_cl,
self.fifo_input_backward_cl, self.signals_medians_cl, self.signals_mads_cl, self.output_backward_cl)
event.wait()
#~ event.wait()
start = pos-self.backward_chunksize
if start<-self.lostfront_chunksize:
return None, None
pos2 = pos-self.lostfront_chunksize
event = pyopencl.enqueue_copy(self.queue, self.output_backward, self.output_backward_cl)
if start>0:
data2 = self.output_backward[:self.chunksize, :]
else:
data2 = self.output_backward[self.lostfront_chunksize:self.chunksize, :]
data2 = data2.copy()
if self.common_ref_removal:
#TODO make OpenCL for this
# removal ref
if self.common_ref_removal:
data2 -= np.median(data2, axis=1)[:, None]
#normalize
if self.normalize:
# OpenCL for this when no common_ref_removal
data2 -= self.signals_medians
data2 /= self.signals_mads
return pos2, data2
示例15: apply_processor
# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import enqueue_copy [as 別名]
def apply_processor(self, pos, sigs_chunk):
if self._plot_debug:
print('apply_processor')
assert sigs_chunk.shape[0]==self.chunksize
if not sigs_chunk.flags['C_CONTIGUOUS'] or sigs_chunk.dtype!=self.internal_dtype:
sigs_chunk = np.ascontiguousarray(sigs_chunk, dtype=self.internal_dtype)
if self.already_processed:
abs_head_index, preprocessed_chunk = pos, sigs_chunk
pyopencl.enqueue_copy(self.queue, self.sigs_chunk_cl, sigs_chunk)
else:
if self.signalpreprocessor.common_ref_removal:
# because not done in kernel yet
raise NotImplemenentedError
abs_head_index, preprocessed_chunk = self.signalpreprocessor.process_data(pos, sigs_chunk)
# roll fifo
gsize = self.fifo_roll_size * self.nb_channel
global_size = (self.fifo_roll_size, self.nb_channel)
if gsize > self.max_wg_size:
local_size = (1, self.nb_channel)
else:
local_size = global_size
event = pyopencl.enqueue_nd_range_kernel(self.queue, self.kern_roll_fifo, global_size, local_size,)
# add new buffer to fifo residuals
gsize = self.chunksize * self.nb_channel
global_size = (self.chunksize, self.nb_channel)
if gsize > self.max_wg_size:
local_size = (1, self.nb_channel)
else:
local_size = global_size
event = pyopencl.enqueue_nd_range_kernel(self.queue, self.kern_add_fifo_residuals, global_size, local_size,)
# TODO call preprocessor kernel and add_fifo_residuals
#~ abs_head_index, preprocessed_chunk = self.signalpreprocessor.process_data(pos, sigs_chunk)
#~ if self._debug_cl:
#~ pyopencl.enqueue_copy(self.queue, self.fifo_residuals, self.fifo_residuals_cl)
#~ fig, ax = plt.subplots()
#~ ax.plot(self.fifo_residuals)
#~ plt.show()
return abs_head_index, preprocessed_chunk