Skip to content

Commit

Permalink
[refactor] Move Context to taichi/program (#1788)
Browse files Browse the repository at this point in the history
* [refactor] Move Context to taichi/program

* fix cuda

* more fix..
  • Loading branch information
k-ye authored Aug 28, 2020
1 parent 7fa0d9d commit da41c85
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 28 deletions.
11 changes: 7 additions & 4 deletions taichi/backends/cuda/jit_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
#include "llvm/Target/TargetMachine.h"
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"

#include "taichi/backends/cuda/cuda_driver.h"
#include "taichi/backends/cuda/cuda_context.h"
#include "taichi/backends/cuda/cuda_driver.h"
#include "taichi/jit/jit_session.h"
#include "taichi/lang_util.h"
#include "taichi/program/program.h"
#include "taichi/runtime/llvm/context.h"
#include "taichi/system/timer.h"
#include "taichi/lang_util.h"
#include "taichi/jit/jit_session.h"
#include "taichi/util/file_sequence_writer.h"

#define TI_RUNTIME_HOST
#include "taichi/program/context.h"
#undef TI_RUNTIME_HOST

TLANG_NAMESPACE_BEGIN

#if defined(TI_WITH_CUDA)
Expand Down
2 changes: 1 addition & 1 deletion taichi/backends/metal/kernel_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "taichi/program/kernel.h"
#define TI_RUNTIME_HOST
#include "taichi/runtime/llvm/context.h"
#include "taichi/program/context.h"
#undef TI_RUNTIME_HOST

TLANG_NAMESPACE_BEGIN
Expand Down
2 changes: 1 addition & 1 deletion taichi/program/async_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "taichi/ir/ir.h"
#include "taichi/ir/statements.h"
#include "taichi/lang_util.h"
#include "taichi/runtime/llvm/context.h"
#include "taichi/program/context.h"

TLANG_NAMESPACE_BEGIN

Expand Down
22 changes: 4 additions & 18 deletions taichi/runtime/llvm/context.h → taichi/program/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "taichi/inc/constants.h"

#if defined(TI_RUNTIME_HOST)
namespace taichi::lang {
using namespace taichi;
namespace taichi {
namespace lang {
#endif

struct LLVMRuntime;
Expand Down Expand Up @@ -36,21 +36,7 @@ struct Context {
#endif
};

struct MemRequest {
std::size_t size;
std::size_t alignment;
uint8 *ptr;
std::size_t __padding;
};

static_assert((sizeof(MemRequest) & (sizeof(MemRequest) - 1)) == 0);

struct MemRequestQueue {
MemRequest requests[taichi_max_num_mem_requests];
int tail;
int processed;
};

#if defined(TI_RUNTIME_HOST)
}
} // namespace lang
} // namespace taichi
#endif
2 changes: 1 addition & 1 deletion taichi/program/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "taichi/backends/cc/cc_program.h"
#include "taichi/program/kernel.h"
#include "taichi/program/kernel_profiler.h"
#include "taichi/runtime/llvm/context.h"
#include "taichi/program/context.h"
#include "taichi/runtime/runtime.h"
#include "taichi/backends/metal/struct_metal.h"
#include "taichi/system/memory_pool.h"
Expand Down
29 changes: 29 additions & 0 deletions taichi/runtime/llvm/mem_request.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

// Use relative path here for runtime compilation
#include "taichi/inc/constants.h"

#if defined(TI_RUNTIME_HOST)
namespace taichi {
namespace lang {
#endif

struct MemRequest {
std::size_t size;
std::size_t alignment;
uint8 *ptr;
std::size_t __padding;
};

static_assert((sizeof(MemRequest) & (sizeof(MemRequest) - 1)) == 0);

struct MemRequestQueue {
MemRequest requests[taichi_max_num_mem_requests];
int tail;
int processed;
};

#if defined(TI_RUNTIME_HOST)
} // namespace lang
} // namespace taichi
#endif
5 changes: 3 additions & 2 deletions taichi/runtime/llvm/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ struct PhysicalCoordinates {

STRUCT_FIELD_ARRAY(PhysicalCoordinates, val);

#include "context.h"
#include "taichi/program/context.h"
#include "taichi/runtime/llvm/mem_request.h"

STRUCT_FIELD_ARRAY(Context, args);
STRUCT_FIELD(Context, runtime);
Expand All @@ -324,7 +325,7 @@ int32 Context_get_extra_args(Context *ctx, int32 i, int32 j) {
return ctx->extra_args[i][j];
}

#include "atomic.h"
#include "taichi/runtime/llvm/atomic.h"

// These structures are accessible by both the LLVM backend and this C++ runtime
// file here (for building complex runtime functions in C++)
Expand Down
2 changes: 1 addition & 1 deletion taichi/system/memory_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "taichi/common/core.h"
#include "taichi/system/unified_allocator.h"
#define TI_RUNTIME_HOST
#include "taichi/runtime/llvm/context.h"
#include "taichi/runtime/llvm/mem_request.h"

#include <mutex>
#include <vector>
Expand Down

0 comments on commit da41c85

Please sign in to comment.