Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#33 from Superjomn/fea/init-module
Browse files Browse the repository at this point in the history
fea/init module
  • Loading branch information
Superjomn authored Feb 20, 2020
2 parents 41e59a5 + cbdd1e0 commit 78be2c3
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 6 deletions.
1 change: 1 addition & 0 deletions cinn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ add_subdirectory(poly)
add_subdirectory(schedule)
add_subdirectory(runtime)
add_subdirectory(ir)
add_subdirectory(backends)
add_subdirectory(lang)
add_subdirectory(optim)
4 changes: 4 additions & 0 deletions cinn/backends/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cc_library(
backends
SRCS outputs.cc
)
5 changes: 5 additions & 0 deletions cinn/backends/outputs.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "cinn/lang/outputs.h"

namespace cinn {
namespace lang {} // namespace lang
} // namespace cinn
40 changes: 40 additions & 0 deletions cinn/backends/outputs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once
#include <string>

namespace cinn {
namespace backends {

/**
* A struct specifying a collection of outputs.
*/
struct Outputs {
//! The name of the emitted object file. Empty if no object file is desired.
std::string object_name;

//! The name of the emitted llvm bitcode. Empty if no bitcode file is desired.
std::string bitcode_name;

//! The name of the emitted C header file.
std::string c_header_name;

Outputs object(const std::string& name) const {
Outputs updated = *this;
updated.object_name = name;
return updated;
}

Outputs bitcode(const std::string& name) const {
Outputs updated = *this;
updated.bitcode_name = name;
return updated;
}

Outputs c_header(const std::string& name) const {
Outputs updated = *this;
updated.c_header_name = name;
return updated;
}
};

} // namespace backends
} // namespace cinn
1 change: 1 addition & 0 deletions cinn/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cc_library(common
SRCS shared.cc pod_value.cc type.cc
target.cc
object.cc
graph_utils.cc
context.cc
Expand Down
4 changes: 4 additions & 0 deletions cinn/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "cinn/common/graph_utils.h"
#include "cinn/common/pod_value.h"
#include "cinn/common/shared.h"
#include "cinn/common/target.h"
#include "cinn/common/type.h"
#include "target.h"

namespace cinn {

Expand All @@ -22,4 +24,6 @@ using common::Float;
using common::Int;
using common::type_of;

using common::Target;

} // namespace cinn
6 changes: 3 additions & 3 deletions cinn/utils/target.cc → cinn/common/target.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "cinn/utils/target.h"
#include "cinn/common/target.h"

namespace cinn {
namespace utils {
namespace common {

bool Target::operator==(const Target &other) const {
return os == other.os && //
Expand All @@ -10,5 +10,5 @@ bool Target::operator==(const Target &other) const {
features == other.features;
}

} // namespace utils
} // namespace common
} // namespace cinn
4 changes: 2 additions & 2 deletions cinn/utils/target.h → cinn/common/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <vector>

namespace cinn {
namespace utils {
namespace common {

struct Target {
/**
Expand Down Expand Up @@ -46,5 +46,5 @@ struct Target {
bool operator==(const Target& other) const;
bool operator!=(const Target& other) const { return !(*this == other); }
};
} // namespace utils
} // namespace common
} // namespace cinn
1 change: 1 addition & 0 deletions cinn/lang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cc_library(lang SRCS
compute.cc
placeholder.cc
tensor.cc
module.cc
DEPS ir poly runtime)

cc_test(test_compute SRCS compute_test.cc DEPS lang)
Expand Down
46 changes: 46 additions & 0 deletions cinn/lang/module.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "cinn/lang/module.h"

namespace cinn {
namespace lang {

/**
* Content of a module.
*/
struct _Module_ : Object {
std::string name;
Target target;
std::vector<ir::Buffer> buffers;
std::vector<ir::PackedFunc> functions;
std::vector<Module> submodules;

const char *type_info() const override { return "_Module_"; }
};

_Module_ *Module::self() { return module_->As<_Module_>(); }
const _Module_ *Module::self() const { return module_->As<_Module_>(); }

Module::Module(const std::string &name, const Target &target) : module_(make_shared<_Module_>()) {
self()->name = name;
self()->target = target;
}

const Target &Module::target() const { return self()->target; }

const std::string &Module::name() const { return self()->name; }

const std::vector<ir::Buffer> &Module::buffers() const { return self()->buffers; }

const std::vector<ir::PackedFunc> &Module::functions() const { return self()->functions; }

const std::vector<Module> &Module::submodules() const { return self()->submodules; }

void Module::Append(const ir::Buffer &buffer) { self()->buffers.push_back(buffer); }

void Module::Append(const ir::PackedFunc &function) { self()->functions.push_back(function); }

void Module::Append(const Module &module) { self()->submodules.push_back(module); }

void Module::Compile(const backends::Outputs &outputs) const {}

} // namespace lang
} // namespace cinn
53 changes: 53 additions & 0 deletions cinn/lang/module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma once
#include <string>
#include <vector>

#include "cinn/backends/outputs.h"
#include "cinn/common/common.h"
#include "cinn/ir/buffer.h"
#include "cinn/ir/function.h"

namespace cinn {
namespace lang {

class _Module_;

/**
* Module represents IR containing lowered function definitions and buffers.
*/
class Module {
public:
Module(const std::string& name, const Target& target);

//! Get the target of this module.
const Target& target() const;

//! Get the name of the module.
const std::string& name() const;

//! The members in the module.
// @{
const std::vector<ir::Buffer>& buffers() const;
const std::vector<ir::PackedFunc>& functions() const;
const std::vector<Module>& submodules() const;
// @}

//! Add something to this module.
// @{
void Append(const ir::Buffer& buffer);
void Append(const ir::PackedFunc& function);
void Append(const Module& module);
// @}

//! Compile a module to some outputs.
void Compile(const backends::Outputs& outputs) const;

_Module_* self();
const _Module_* self() const;

private:
Shared<_Module_> module_;
};

} // namespace lang
} // namespace cinn
Empty file removed cinn/runtime/module.cc
Empty file.
Empty file removed cinn/runtime/module.h
Empty file.
1 change: 0 additions & 1 deletion cinn/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cc_library(utils SRCS string.cc
target.cc
functional.cc
)

0 comments on commit 78be2c3

Please sign in to comment.