def __call__(self, x): if self.has_uninitialized_params: self._initialize_params(x.size // x.shape[0]) if not hasattr(x, "cdata"): x_, x_cdata = utils.malloc_cma_ndarray(x.shape) x_ = Variable(x_) x_.cdata = x_cdata np.copyto(x_.data, x.data) x = x_ return F.Linear(x, self.W)
def forward(self, inputs): self.accel_fn = overlays.Mmult() x = inputs[0] w = inputs[1] x_nrows, x_ncols = x.shape w_nrows, w_ncols = w.shape assert x_ncols == w_ncols # TODO 使いまわしたい y, y_cdata = utils.malloc_cma_ndarray((x_nrows, w_nrows)) y = Variable(y) y.cdata = y_cdata self.accel_fn(x.cdata, w.cdata, y.cdata, x_nrows, w_nrows, x_ncols) return y
def add_param(self, name, shape, dtype=np.float32, initializer=None): """Registers a parameter to the link. """ d = self.__dict__ if name in d: raise AttributeError( 'cannot register a new parameter %s: attribute exists' % name) if initializer is not None: raise AttributeError('initializer is not supported') data, cdata = utils.malloc_cma_ndarray(shape) var = Variable(data, volatile='auto', name=name) var.cdata = cdata print('init model cma array', name, cdata, var) self._params.append(name) d[name] = var if name in self._uninitialized_params: del self._uninitialized_params[name]