Skip to content

Commit

Permalink
Add initial version of GPU-based port mapper class.
Browse files Browse the repository at this point in the history
  • Loading branch information
lebedov committed Feb 10, 2015
1 parent f3063a4 commit 890a15b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions neurokernel/pm_gpu.py
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


0 comments on commit 890a15b

Please sign in to comment.