From 767a822ea37ba75314babc530e2f2498ff367427 Mon Sep 17 00:00:00 2001 From: jim19930609 Date: Wed, 8 Jun 2022 16:48:18 +0800 Subject: [PATCH] Renamed and rearranged FieldCacheData --- taichi/llvm/llvm_offline_cache.h | 50 ++++++++++++++++---------------- taichi/llvm/llvm_program.cpp | 8 ++--- taichi/llvm/llvm_program.h | 5 ++-- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/taichi/llvm/llvm_offline_cache.h b/taichi/llvm/llvm_offline_cache.h index 9b7cfac88b55b4..6fa243bed79a7c 100644 --- a/taichi/llvm/llvm_offline_cache.h +++ b/taichi/llvm/llvm_offline_cache.h @@ -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 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, @@ -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 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 fields; // key = snode_tree_id + std::unordered_map fields; // key = snode_tree_id std::unordered_map kernels; // key = kernel_name diff --git a/taichi/llvm/llvm_program.cpp b/taichi/llvm/llvm_program.cpp index eea60dad165f79..db58cfc616a60a 100644 --- a/taichi/llvm/llvm_program.cpp +++ b/taichi/llvm/llvm_program.cpp @@ -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) { @@ -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; diff --git a/taichi/llvm/llvm_program.h b/taichi/llvm/llvm_program.h index 69378ee660bf1f..34d3e12c5b2451 100644 --- a/taichi/llvm/llvm_program.h +++ b/taichi/llvm/llvm_program.h @@ -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);