Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] Move support related code to include/tvm/support #4716

Merged
merged 2 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions apps/cpp_rpc/rpc_env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void LinuxShared(const std::string output,
}
cmd += " " + options;
std::string err_msg;
auto executed_status = common::Execute(cmd, &err_msg);
auto executed_status = support::Execute(cmd, &err_msg);
if (executed_status) {
LOG(FATAL) << err_msg;
}
Expand Down Expand Up @@ -195,22 +195,22 @@ void CreateShared(const std::string output, const std::vector<std::string> &file
*/
Module Load(std::string *fileIn, const std::string fmt) {
std::string file = *fileIn;
if (common::EndsWith(file, ".so")) {
if (support::EndsWith(file, ".so")) {
return Module::LoadFromFile(file, fmt);
}

#if defined(__linux__) || defined(__ANDROID__)
std::string file_name = file + ".so";
if (common::EndsWith(file, ".o")) {
if (support::EndsWith(file, ".o")) {
std::vector<std::string> files;
files.push_back(file);
CreateShared(file_name, files);
} else if (common::EndsWith(file, ".tar")) {
} else if (support::EndsWith(file, ".tar")) {
std::string tmp_dir = "./rpc/tmp/";
mkdir(&tmp_dir[0], 0777);
std::string cmd = "tar -C " + tmp_dir + " -zxf " + file;
std::string err_msg;
int executed_status = common::Execute(cmd, &err_msg);
int executed_status = support::Execute(cmd, &err_msg);
if (executed_status) {
LOG(FATAL) << err_msg;
}
Expand Down
18 changes: 9 additions & 9 deletions apps/cpp_rpc/rpc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ class RPCServer {
void ListenLoopProc() {
TrackerClient tracker(tracker_addr_, key_, custom_addr_);
while (true) {
common::TCPSocket conn;
common::SockAddr addr("0.0.0.0", 0);
support::TCPSocket conn;
support::SockAddr addr("0.0.0.0", 0);
std::string opts;
try {
// step 1: setup tracker and report to tracker
Expand Down Expand Up @@ -221,8 +221,8 @@ class RPCServer {
* \param ping_period Timeout for select call waiting
*/
void AcceptConnection(TrackerClient* tracker,
common::TCPSocket* conn_sock,
common::SockAddr* addr,
support::TCPSocket* conn_sock,
support::SockAddr* addr,
std::string* opts,
int ping_period = 2) {
std::set <std::string> old_keyset;
Expand All @@ -233,7 +233,7 @@ class RPCServer {

while (true) {
tracker->WaitConnectionAndUpdateKey(listen_sock_, my_port_, ping_period, &matchkey);
common::TCPSocket conn = listen_sock_.Accept(addr);
support::TCPSocket conn = listen_sock_.Accept(addr);

int code = kRPCMagic;
CHECK_EQ(conn.RecvAll(&code, sizeof(code)), sizeof(code));
Expand Down Expand Up @@ -289,7 +289,7 @@ class RPCServer {
* \param sock The socket information
* \param addr The socket address information
*/
void ServerLoopProc(common::TCPSocket sock, common::SockAddr addr) {
void ServerLoopProc(support::TCPSocket sock, support::SockAddr addr) {
// Server loop
auto env = RPCEnv();
RPCServerLoop(sock.sockfd);
Expand All @@ -308,7 +308,7 @@ class RPCServer {

if (opts.find(option) == 0) {
cmd = opts.substr(opts.find_last_of(option) + 1);
CHECK(common::IsNumber(cmd)) << "Timeout is not valid";
CHECK(support::IsNumber(cmd)) << "Timeout is not valid";
return std::stoi(cmd);
}
return 0;
Expand All @@ -321,8 +321,8 @@ class RPCServer {
std::string tracker_addr_;
std::string key_;
std::string custom_addr_;
common::TCPSocket listen_sock_;
common::TCPSocket tracker_sock_;
support::TCPSocket listen_sock_;
support::TCPSocket tracker_sock_;
};

/*!
Expand Down
12 changes: 6 additions & 6 deletions apps/cpp_rpc/rpc_tracker_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ class TrackerClient {
* \param ping_period Select wait time.
* \param matchkey Random match key output.
*/
void WaitConnectionAndUpdateKey(common::TCPSocket listen_sock,
void WaitConnectionAndUpdateKey(support::TCPSocket listen_sock,
int port,
int ping_period,
std::string *matchkey) {
int unmatch_period_count = 0;
int unmatch_timeout = 4;
while (true) {
if (!tracker_sock_.IsClosed()) {
common::PollHelper poller;
support::PollHelper poller;
poller.WatchRead(listen_sock.sockfd);
poller.Poll(ping_period * 1000);
if (!poller.CheckRead(listen_sock.sockfd)) {
Expand Down Expand Up @@ -189,11 +189,11 @@ class TrackerClient {
* \param retry_period Number of seconds before we retry again.
* \return TCPSocket The socket information if connect is success.
*/
common::TCPSocket ConnectWithRetry(int timeout = 60, int retry_period = 5) {
support::TCPSocket ConnectWithRetry(int timeout = 60, int retry_period = 5) {
auto tbegin = std::chrono::system_clock::now();
while (true) {
common::SockAddr addr(tracker_addr_);
common::TCPSocket sock;
support::SockAddr addr(tracker_addr_);
support::TCPSocket sock;
sock.Create();
LOG(INFO) << "Tracker connecting to " << addr.AsString();
if (sock.Connect(addr)) {
Expand Down Expand Up @@ -235,7 +235,7 @@ class TrackerClient {
std::string tracker_addr_;
std::string key_;
std::string custom_addr_;
common::TCPSocket tracker_sock_;
support::TCPSocket tracker_sock_;
std::set <std::string> old_keyset_;
std::mt19937 gen_;
std::uniform_real_distribution<float> dis_;
Expand Down
2 changes: 2 additions & 0 deletions include/tvm/arithmetic.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#ifndef TVM_ARITHMETIC_H_
#define TVM_ARITHMETIC_H_

#include <tvm/support/with.h>

#include <vector>
#include <unordered_map>
#include <memory>
Expand Down
1 change: 0 additions & 1 deletion include/tvm/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include <string>

#include "base.h"
#include "expr.h"
#include "expr_operator.h"
#include "tvm/node/container.h"
Expand Down
1 change: 0 additions & 1 deletion include/tvm/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#define TVM_CODEGEN_H_

#include <string>
#include "base.h"
#include "expr.h"
#include "lowered_func.h"
#include "runtime/packed_func.h"
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/data_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#ifndef TVM_DATA_LAYOUT_H_
#define TVM_DATA_LAYOUT_H_

#include <tvm/base.h>

#include <tvm/expr.h>

#include <string>
Expand Down
1 change: 0 additions & 1 deletion include/tvm/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <algorithm>
#include <unordered_map>
#include <iostream>
#include "base.h"
#include "node/node.h"
#include "node/container.h"
#include "node/functor.h"
Expand Down
1 change: 0 additions & 1 deletion include/tvm/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <string>
#include <vector>
#include <utility>
#include "base.h"
#include "expr.h"
#include "runtime/util.h"

Expand Down
8 changes: 8 additions & 0 deletions include/tvm/ir/op.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ class OpMap {
const GenericOpMap& map_;
};

#define TVM_STRINGIZE_DETAIL(x) #x
#define TVM_STRINGIZE(x) TVM_STRINGIZE_DETAIL(x)
#define TVM_DESCRIBE(...) describe(__VA_ARGS__ "\n\nFrom:" __FILE__ ":" TVM_STRINGIZE(__LINE__))
/*!
* \brief Macro to include current line as string
*/
#define TVM_ADD_FILELINE "\n\nDefined in " __FILE__ ":L" TVM_STRINGIZE(__LINE__)

// internal macros to make
#define TVM_OP_REGISTER_VAR_DEF \
static DMLC_ATTRIBUTE_UNUSED ::tvm::OpRegistry& __make_##Op
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/ir/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#ifndef TVM_IR_TRANSFORM_H_
#define TVM_IR_TRANSFORM_H_

#include <tvm/base.h>
#include <tvm/support/with.h>
#include <tvm/node/container.h>
#include <tvm/ir/error.h>
#include <tvm/ir/module.h>
Expand Down
1 change: 0 additions & 1 deletion include/tvm/lowered_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include <string>

#include "base.h"
#include "expr.h"
#include "tensor.h"
#include "tvm/node/container.h"
Expand Down
1 change: 0 additions & 1 deletion include/tvm/packed_func_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <limits>
#include <type_traits>

#include "base.h"
#include "expr.h"
#include "tensor.h"
#include "runtime/packed_func.h"
Expand Down
1 change: 0 additions & 1 deletion include/tvm/schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include <string>
#include <unordered_map>
#include "base.h"
#include "expr.h"
#include "tensor.h"
#include "tensor_intrin.h"
Expand Down
1 change: 0 additions & 1 deletion include/tvm/schedule_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#ifndef TVM_SCHEDULE_PASS_H_
#define TVM_SCHEDULE_PASS_H_

#include "base.h"
#include "schedule.h"

namespace tvm {
Expand Down
8 changes: 4 additions & 4 deletions include/tvm/logging.h → include/tvm/support/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
*/

/*!
* \file tvm/logging.h
* \file tvm/support/logging.h
* \brief logging utilities on top of dmlc-core
*/
#ifndef TVM_LOGGING_H_
#define TVM_LOGGING_H_
#ifndef TVM_SUPPORT_LOGGING_H_
#define TVM_SUPPORT_LOGGING_H_

// a technique that enables overriding macro names on the number of parameters. This is used
// to define other macros below
Expand Down Expand Up @@ -114,4 +114,4 @@
#define COND_CHECK_2(quit_on_assert, x) COND_CHECK_3(quit_on_assert, x, return false)
#define COND_LOG_2(quit_on_assert, x) COND_LOG_3(quit_on_assert, x, return false)

#endif // TVM_LOGGING_H_
#endif // TVM_SUPPORT_LOGGING_H_
20 changes: 6 additions & 14 deletions include/tvm/base.h → include/tvm/support/with.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
*/

/*!
* \file tvm/base.h
* \brief Base utilities
* \file tvm/support/with.h
* \brief RAII wrapper function to enter and exit a context object
* similar to python's with syntax.
*/
#ifndef TVM_BASE_H_
#define TVM_BASE_H_
#ifndef TVM_SUPPORT_WITH_H_
#define TVM_SUPPORT_WITH_H_

#include <dmlc/logging.h>
#include <utility>
Expand Down Expand Up @@ -73,14 +74,5 @@ class With {
ContextType ctx_;
};

#define TVM_STRINGIZE_DETAIL(x) #x
#define TVM_STRINGIZE(x) TVM_STRINGIZE_DETAIL(x)
#define TVM_DESCRIBE(...) describe(__VA_ARGS__ "\n\nFrom:" __FILE__ ":" TVM_STRINGIZE(__LINE__))
/*!
* \brief Macro to include current line as string
*/
#define TVM_ADD_FILELINE "\n\nDefined in " __FILE__ ":L" TVM_STRINGIZE(__LINE__)


} // namespace tvm
#endif // TVM_BASE_H_
#endif // TVM_SUPPORT_WITH_H_
1 change: 0 additions & 1 deletion include/tvm/target_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#define TVM_TARGET_INFO_H_

#include <string>
#include "base.h"
#include "expr.h"

namespace tvm {
Expand Down
1 change: 0 additions & 1 deletion include/tvm/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <utility>
#include <type_traits>

#include "base.h"
#include "expr.h"
#include "expr_operator.h"
#include "arithmetic.h"
Expand Down
2 changes: 1 addition & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Header files in include are public APIs that share across modules.
There can be internal header files within each module that sit in src.

## Modules
- common: Internal common utilities.
- support: Internal support utilities.
- runtime: Minimum runtime related codes.
- node: base infra for IR/AST nodes that is dialect independent.
- api: API function registration.
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/codegen_cuda.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/*!
* \file codegen_cuda.cc
*/
#include <tvm/base.h>

#include <tvm/runtime/registry.h>
#include <tvm/packed_func_ext.h>
#include <cmath>
Expand Down
6 changes: 3 additions & 3 deletions src/codegen/llvm/llvm_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand All @@ -22,7 +22,7 @@
*/
#ifdef TVM_LLVM_VERSION

#include <tvm/base.h>
#include <dmlc/logging.h>
#include <atomic>
#include <mutex>
#include <memory>
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/opt/build_cuda_on.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <sys/stat.h>
#endif
#include <cuda_runtime.h>
#include <tvm/base.h>

#include <nvrtc.h>
#include <cstdlib>

Expand Down
2 changes: 1 addition & 1 deletion src/lang/expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/*!
* \file expr.cc
*/
#include <tvm/base.h>

#include <tvm/expr.h>
#include <tvm/ir.h>
#include <tvm/expr_operator.h>
Expand Down
2 changes: 1 addition & 1 deletion src/lang/expr_operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/*!
* \file expr_operator.cc
*/
#include <tvm/base.h>

#include <tvm/ir.h>
#include <tvm/expr_operator.h>
#include <cmath>
Expand Down
2 changes: 1 addition & 1 deletion src/lang/ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/*!
* \file ir.cc
*/
#include <tvm/base.h>

#include <tvm/expr.h>
#include <tvm/ir.h>
#include <tvm/ir_pass.h>
Expand Down
Loading