Skip to content

Commit

Permalink
Renamed and rearranged FieldCacheData
Browse files Browse the repository at this point in the history
  • Loading branch information
jim19930609 committed Jun 8, 2022
1 parent c71a376 commit 767a822
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
50 changes: 25 additions & 25 deletions taichi/llvm/llvm_offline_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@
namespace taichi {
namespace lang {

struct CompiledFieldData {
struct CompiledSNodeData {
int id;
SNodeType type = SNodeType::undefined;
size_t cell_size_bytes{0};
size_t chunk_size{0};

TI_IO_DEF(id, type, cell_size_bytes, chunk_size);
};

int tree_id{0};
int root_id{0};
size_t root_size{0};
std::vector<CompiledSNodeData> snode_metas;

TI_IO_DEF(tree_id, root_id, root_size, snode_metas);

// TODO(zhanlue)
// Serialize/Deserialize the llvm::Module from StructCompiler
// At runtime, make sure loaded Field-Modules and Kernel-Modules are linked
// altogether.
};

struct LlvmOfflineCache {
enum Format {
LL = 0x01,
Expand Down Expand Up @@ -42,34 +65,11 @@ struct LlvmOfflineCache {
TI_IO_DEF(kernel_key, args, offloaded_task_list);
};

struct FieldCacheData {
struct SNodeCacheData {
int id;
SNodeType type = SNodeType::undefined;
size_t cell_size_bytes{0};
size_t chunk_size{0};

TI_IO_DEF(id, type, cell_size_bytes, chunk_size);
};

int tree_id{0};
int root_id{0};
size_t root_size{0};
std::vector<SNodeCacheData> snode_metas;

TI_IO_DEF(tree_id, root_id, root_size, snode_metas);

// TODO(zhanlue)
// Serialize/Deserialize the llvm::Module from StructCompiler
// At runtime, make sure loaded Field-Modules and Kernel-Modules are linked
// altogether.
};

// TODO(zhanlue): we need a better identifier for each FieldCacheData
// TODO(zhanlue): we need a better identifier for each CompiledFieldData
// (SNodeTree) Given that snode_tree_id is not continuous, it is ridiculous to
// ask the users to remember each of the snode_tree_ids
// ** Find a way to name each SNodeTree **
std::unordered_map<int, FieldCacheData> fields; // key = snode_tree_id
std::unordered_map<int, CompiledFieldData> fields; // key = snode_tree_id

std::unordered_map<std::string, KernelCacheData>
kernels; // key = kernel_name
Expand Down
8 changes: 4 additions & 4 deletions taichi/llvm/llvm_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ LlvmProgramImpl::clone_struct_compiler_initial_context(
}

void LlvmProgramImpl::initialize_llvm_runtime_snodes(
const LlvmOfflineCache::FieldCacheData &field_cache_data,
const CompiledFieldData &field_cache_data,
uint64 *result_buffer) {
TaichiLLVMContext *tlctx = nullptr;
if (config->arch == Arch::cuda) {
Expand Down Expand Up @@ -276,17 +276,17 @@ void LlvmProgramImpl::compile_snode_tree_types(SNodeTree *tree) {
compile_snode_tree_types_impl(tree);
}

static LlvmOfflineCache::FieldCacheData construct_filed_cache_data(
static CompiledFieldData construct_filed_cache_data(
const SNodeTree &tree,
const StructCompiler &struct_compiler) {
LlvmOfflineCache::FieldCacheData ret;
CompiledFieldData ret;
ret.tree_id = tree.id();
ret.root_id = tree.root()->id;
ret.root_size = struct_compiler.root_size;

const auto &snodes = struct_compiler.snodes;
for (size_t i = 0; i < snodes.size(); i++) {
LlvmOfflineCache::FieldCacheData::SNodeCacheData snode_cache_data;
CompiledFieldData::CompiledSNodeData snode_cache_data;
snode_cache_data.id = snodes[i]->id;
snode_cache_data.type = snodes[i]->type;
snode_cache_data.cell_size_bytes = snodes[i]->cell_size_bytes;
Expand Down
5 changes: 2 additions & 3 deletions taichi/llvm/llvm_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ class LlvmProgramImpl : public ProgramImpl {
/**
* Initializes the SNodes for LLVM based backends.
*/
void initialize_llvm_runtime_snodes(
const LlvmOfflineCache::FieldCacheData &field_cache_data,
uint64 *result_buffer);
void initialize_llvm_runtime_snodes(const CompiledFieldData &field_cache_data,
uint64 *result_buffer);

uint64 fetch_result_uint64(int i, uint64 *result_buffer);

Expand Down

0 comments on commit 767a822

Please sign in to comment.