Reorganize code to write batches out to gpu caches