-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial version of GPU-based port mapper class.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Port mapper for GPU memory. | ||
""" | ||
|
||
import numpy as np | ||
import pycuda.gpuarray as gpuarray | ||
|
||
from plsel import BasePortMapper | ||
|
||
class GPUPortMapper(PortMapper): | ||
def __init__(self, selector, data=None, portmap=None): | ||
super(PortMapper, self).__init__(selector, portmap) | ||
N = len(self) | ||
|
||
if data is None or len(data) == 0: | ||
self.data = gpuarray.empty(0, np.double) | ||
else: | ||
assert np.ndim(data) == 1 | ||
assert type(data) == gpuarray.GPUArray | ||
|
||
# The integers in the port map must be valid indices into the | ||
# data array: | ||
assert max(self.portmap) < len(data) | ||
|
||
# The port mapper may map identifiers to some portion of the data array: | ||
assert N <= len(data) | ||
self.data = data.copy() | ||
|
||
def get_inds_nonzero(self): | ||
raise NotImplementedError | ||
|
||
def get_ports_nonzero(self): | ||
raise NotImplementedError | ||
|
||
def get_by_inds(self, inds): | ||
raise NotImplementedError | ||
|
||
def set_by_ind(self, inds, data): | ||
# Can be implemented using scikits.cuda.misc.set_by_index | ||
raise NotImplementedError | ||
|
||
|