def _oper_gpu(cls, lhs, rhs): log_lhs = log(lhs + 1e-8) ret = cls._create_node(-cu.cusum(get_gpu(log_lhs * rhs))) ret.attrs._log_lhs = log_lhs ret.attrs._rhs = rhs ret.attrs._lhs = lhs return ret
def _oper_gpu(cls, lhs, rhs, clip): N = len(lhs) value = cu.cusum(get_gpu((get_gpu(lhs) - get_gpu(rhs)) ** 2)) / (N * 2) ret = cls._create_node(value) ret.attrs._lhs = lhs ret.attrs._rhs = rhs ret.attrs._clip = clip return ret
def _oper_gpu(cls, lhs, rhs): N = lhs.shape[0] z = softmax(lhs) tmp1 = get_gpu(lhs).empty_like_me() cu.cucross_entropy(get_gpu(z), get_gpu(rhs), get_gpu(tmp1)) loss = -cu.cusum(get_gpu(tmp1)) / N ret = cls._create_node(loss) ret.attrs._z = z ret.attrs._lhs = lhs ret.attrs._rhs = rhs return ret
def _oper_gpu(cls, lhs, rhs): N = lhs.shape[0] z = get_gpu(lhs).empty_like_me() tmp1 = get_gpu(lhs).empty_like_me() with cu.cudnn_handler() as handle: cu.cuSoftmaxForward(handle, lhs, z, mode=1) cu.cucross_entropy(get_gpu(z), get_gpu(rhs), get_gpu(tmp1)) loss = -cu.cusum(get_gpu(tmp1)) / N ret = cls._create_node(loss) ret.attrs._z = z ret.attrs._lhs = lhs ret.attrs._rhs = rhs return ret
def _oper_gpu(cls, lhs, rhs): N = len(lhs) z = get_gpu(lhs).empty_like_me() tmp1 = get_gpu(lhs).empty_like_me() tmp2 = get_gpu(lhs).empty_like_me() cu.cusigmoid(get_gpu(lhs), z) cu.cucross_entropy(get_gpu(z), get_gpu(rhs), tmp1) cu.cucross_entropy(get_gpu(-z + 1.), get_gpu(-rhs + 1.), tmp2) loss = cu.cusum(-(tmp1 + tmp2)) / N ret = cls._create_node(loss) ret.attrs._z = z ret.attrs._lhs = lhs ret.attrs._rhs = rhs return ret
def _oper_gpu(cls, lhs, rhs): assert rhs.ndim > 1, "Input arrays must have no less than 2 dimension." N = len(lhs) return cu.cusum(get_gpu((get_gpu(lhs) - get_gpu(rhs))**2)) / (N * 2)