def update_core(self):
    self.setup_workers()
    self._send_message(('update', None))
    with cuda.Device(self._devices[0]):
        self._master.cleargrads()
        optimizer = self.get_optimizer('main')
        iterator = self.get_iterator('main')
        batch = iterator.next()
        batch = self.converter(batch, self._devices[0])
        loss = _calc_loss(self._master, batch)
        self._master.cleargrads()
        loss.backward()
        null_stream = cuda.Stream.null
        if (self.comm is not None):
            gg = gather_grads(self._master)
            nccl_data_type = _get_nccl_data_type(gg.dtype)
            self.comm.reduce(gg.data.ptr, gg.data.ptr, gg.size, nccl_data_type, nccl.NCCL_SUM, 0, null_stream.ptr)
            scatter_grads(self._master, gg)
            del gg
        optimizer.update()
        if (self.comm is not None):
            gp = gather_params(self._master)
            nccl_data_type = _get_nccl_data_type(gp.dtype)
            self.comm.bcast(gp.data.ptr, gp.size, nccl_data_type, 0, null_stream.ptr)
        if (self.auto_new_epoch and iterator.is_new_epoch):
            optimizer.new_epoch(auto=True)
def update_core(self):
    self.setup_workers()
    self._send_message(('update', None))
    with cuda.Device(self._devices[0]):
        self._master.cleargrads()
        optimizer = self.get_optimizer('main')
        iterator = self.get_iterator('main')
        batch = iterator.next()
        batch = self.converter(batch, self._devices[0])
        loss = _calc_loss(self._master, batch)
        self._master.cleargrads()
        loss.backward()
        null_stream = cuda.Stream.null
        if (self.comm is not None):
            gg = gather_grads(self._master)
            nccl_data_type = _get_nccl_data_type(gg.dtype)
            self.comm.reduce(gg.data.ptr, gg.data.ptr, gg.size, nccl_data_type, nccl.NCCL_SUM, 0, null_stream.ptr)
            scatter_grads(self._master, gg)
            del gg
        optimizer.update()
        if (self.comm is not None):
            gp = gather_params(self._master)
            nccl_data_type = _get_nccl_data_type(gp.dtype)
            self.comm.bcast(gp.data.ptr, gp.size, nccl_data_type, 0, null_stream.ptr)
        if (self.auto_new_epoch and iterator.is_new_epoch):
            optimizer.new_epoch(auto=True)