Skip to content

Commit

Permalink
put tensorflow into namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoqing committed Dec 10, 2024
1 parent 6d0d595 commit 52be440
Show file tree
Hide file tree
Showing 31 changed files with 352 additions and 163 deletions.
5 changes: 1 addition & 4 deletions src/TensorflowCpy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ else()
find_package(TensorFlow REQUIRED)
else()
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/proto")
add_compile_definitions(ENABLE_TENSORFLOW_CPY=1)
endif()
endif()

Expand Down Expand Up @@ -50,10 +51,6 @@ if(ENABLE_TORCH)
else()
if(USE_LIBTENSORFLOW_CC)
target_include_directories(${PROJECT_NAME} PRIVATE ${TensorFlow_INCLUDE_DIRS})
else()
target_include_directories(
${PROJECT_NAME} PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/tensorflow_cpy>
)
endif()
endif()

Expand Down
41 changes: 41 additions & 0 deletions src/TensorflowCpy/include/tensorflow_cpy/tensorflow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include "./tensorflow/stream_executor/device_memory.h"
#include "./tensorflow/stream_executor/stream_executor_pimpl.h"
#include "./tensorflow/stream_executor/platform.h"

#include "./tensorflow/cc/saved_model/loader.h"
#include "./tensorflow/cc/saved_model/tag_constants.h"

#include "./tensorflow/core/util/stream_executor_util.h"

#include "./tensorflow/core/platform/logging.h"
#include "./tensorflow/core/platform/statusor.h"
#include "./tensorflow/core/platform/refcount.h"
#include "./tensorflow/core/platform/types.h"
#include "./tensorflow/core/platform/macros.h"
#include "./tensorflow/core/platform/status.h"
#include "./tensorflow/core/platform/env.h"

#include "./tensorflow/core/public/session_options.h"
#include "./tensorflow/core/public/session.h"

#include "./tensorflow/core/common_runtime/device_mgr.h"
#include "./tensorflow/core/common_runtime/gpu/gpu_init.h"
#include "./tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.h"
#include "./tensorflow/core/common_runtime/device/device_id_utils.h"
#include "./tensorflow/core/common_runtime/device/device_mem_allocator.h"
#include "./tensorflow/core/common_runtime/device/device_id.h"

#include "./tensorflow/core/framework/allocator.h"
#include "./tensorflow/core/framework/types.h"
#include "./tensorflow/core/framework/tensor_shape.h"
#include "./tensorflow/core/framework/tensor.h"
#include "./tensorflow/core/framework/device.h"
#include "./tensorflow/core/framework/op.h"

namespace tensorflow_cpy {
namespace tensorflow {
using namespace ::tensorflow;
} // namespace tensorflow
} // namespace tensorflow_cpy
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
/// SavedModel loading functions and SavedModelBundle struct.

#ifndef TENSORFLOW_CC_SAVED_MODEL_LOADER_H_
#define TENSORFLOW_CC_SAVED_MODEL_LOADER_H_
#ifndef TENSORFLOW_CPY_CC_SAVED_MODEL_LOADER_H_
#define TENSORFLOW_CPY_CC_SAVED_MODEL_LOADER_H_

#include <string>
#include <unordered_set>

#include "tensorflow/core/platform/status.h"
#include "tensorflow/core/protobuf/meta_graph.pb.h"
#include "tensorflow/core/public/session.h"
#include <tensorflow/core/protobuf/meta_graph.pb.h>
#include "../../core/platform/status.h"
#include "../../core/public/session.h"

// clang-format off
namespace tensorflow_cpy {
namespace tensorflow {
using namespace ::tensorflow;


/// SavedModel representation once the SavedModel is loaded from storage.
Expand Down Expand Up @@ -73,5 +76,8 @@ Status LoadSavedModel(const SessionOptions& session_options,
bool MaybeSavedModelDirectory(const std::string& export_dir);

} // namespace tensorflow
} // namespace tensorflow_cpy
// clang-format on

#endif // TENSORFLOW_CC_SAVED_MODEL_LOADER_H_

#endif // TENSORFLOW_CPY_CC_SAVED_MODEL_LOADER_H_
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef TENSORFLOW_CC_SAVED_MODEL_TAG_CONSTANTS_H_
#define TENSORFLOW_CC_SAVED_MODEL_TAG_CONSTANTS_H_
#ifndef TENSORFLOW_CPY_CC_SAVED_MODEL_TAG_CONSTANTS_H_
#define TENSORFLOW_CPY_CC_SAVED_MODEL_TAG_CONSTANTS_H_

// clang-format off
namespace tensorflow_cpy {
namespace tensorflow {

/// Tag for the `gpu` graph.
Expand All @@ -16,5 +18,8 @@ constexpr char kSavedModelTagServe[] = "serve";
constexpr char kSavedModelTagTrain[] = "train";

} // namespace tensorflow
} // namespace tensorflow_cpy
// clang-format on

#endif // TENSORFLOW_CC_SAVED_MODEL_TAG_CONSTANTS_H_

#endif // TENSORFLOW_CPY_CC_SAVED_MODEL_TAG_CONSTANTS_H_
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#ifndef TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_DEVICE_ID_H_
#define TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_DEVICE_ID_H_
#ifndef TENSORFLOW_CPY_CORE_COMMON_RUNTIME_DEVICE_DEVICE_ID_H_
#define TENSORFLOW_CPY_CORE_COMMON_RUNTIME_DEVICE_DEVICE_ID_H_

#include <cstdint>

// clang-format off
namespace tensorflow_cpy {
namespace tensorflow {

// There are three types of device ids:
Expand Down Expand Up @@ -80,5 +82,8 @@ struct PlatformDeviceId{
};

} // namespace tensorflow
} // namespace tensorflow_cpy
// clang-format on

#endif // TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_DEVICE_ID_H_

#endif // TENSORFLOW_CPY_CORE_COMMON_RUNTIME_DEVICE_DEVICE_ID_H_
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@

#ifndef TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_DEVICE_ID_UTILS_H_
#define TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_DEVICE_ID_UTILS_H_
#ifndef TENSORFLOW_CPY_CORE_COMMON_RUNTIME_DEVICE_DEVICE_ID_UTILS_H_
#define TENSORFLOW_CPY_CORE_COMMON_RUNTIME_DEVICE_DEVICE_ID_UTILS_H_

#include <string>
#include "tensorflow/core/common_runtime/device/device_id.h"
#include "tensorflow/stream_executor/platform.h"
#include "../../../core/common_runtime/device/device_id.h"
#include "../../../stream_executor/platform.h"

// clang-format off
namespace tensorflow_cpy {
namespace tensorflow {
using namespace ::tensorflow;
namespace se = stream_executor;

// Utility methods for translation between TensorFlow device ids and platform
Expand All @@ -27,5 +30,8 @@ class DeviceIdUtil {
};

} // namespace tensorflow
} // namespace tensorflow_cpy
// clang-format on

#endif // TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_DEVICE_ID_UTILS_H_

#endif // TENSORFLOW_CPY_CORE_COMMON_RUNTIME_DEVICE_DEVICE_ID_UTILS_H_
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@

#ifndef TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_DEVICE_MEM_ALLOCATOR_H_
#define TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_DEVICE_MEM_ALLOCATOR_H_
#ifndef TENSORFLOW_CPY_CORE_COMMON_RUNTIME_DEVICE_DEVICE_MEM_ALLOCATOR_H_
#define TENSORFLOW_CPY_CORE_COMMON_RUNTIME_DEVICE_DEVICE_MEM_ALLOCATOR_H_

#include "tensorflow/core/common_runtime/device/device_id.h"
#include "tensorflow/core/framework/allocator.h"
#include "tensorflow/stream_executor/stream_executor_pimpl.h"
#include "../../../core/common_runtime/device/device_id.h"
#include "../../../core/framework/allocator.h"
#include "../../../stream_executor/stream_executor_pimpl.h"

// clang-format off
namespace tensorflow_cpy {
namespace tensorflow {
using namespace ::tensorflow;
namespace se = stream_executor;

// Suballocator for StreamExecutor-based device memory.
Expand Down Expand Up @@ -70,5 +73,8 @@ class DeviceMemAllocator : public SubAllocator {
};

} // namespace tensorflow
} // namespace tensorflow_cpy
// clang-format on

#endif // TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_DEVICE_MEM_ALLOCATOR_H_

#endif // TENSORFLOW_CPY_CORE_COMMON_RUNTIME_DEVICE_DEVICE_MEM_ALLOCATOR_H_
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@

#ifndef TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_MGR_H_
#define TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_MGR_H_
#ifndef TENSORFLOW_CPY_CORE_COMMON_RUNTIME_DEVICE_MGR_H_
#define TENSORFLOW_CPY_CORE_COMMON_RUNTIME_DEVICE_MGR_H_

#include <string>
#include <vector>

#include "tensorflow/core/framework/device.h"
#include "tensorflow/core/framework/device_attributes.pb.h"
#include "tensorflow/core/platform/macros.h"
#include <tensorflow/core/framework/device_attributes.pb.h>
#include "../../core/framework/device.h"
#include "../../core/platform/macros.h"

// clang-format off
namespace tensorflow_cpy {
namespace tensorflow {

class DeviceAttributes;
using namespace ::tensorflow;

// Represents a set of devices.
class DeviceMgr {
Expand Down Expand Up @@ -54,5 +56,8 @@ class DeviceMgr {
static const size_t kStaleDeviceBufferSize = 8192;

} // namespace tensorflow
} // namespace tensorflow_cpy
// clang-format on

#endif // TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_MGR_H_

#endif // TENSORFLOW_CPY_CORE_COMMON_RUNTIME_DEVICE_MGR_H_
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@

#ifndef TENSORFLOW_CORE_COMMON_RUNTIME_GPU_GPU_BFC_ALLOCATOR_H_
#define TENSORFLOW_CORE_COMMON_RUNTIME_GPU_GPU_BFC_ALLOCATOR_H_
#ifndef TENSORFLOW_CPY_CORE_COMMON_RUNTIME_GPU_GPU_BFC_ALLOCATOR_H_
#define TENSORFLOW_CPY_CORE_COMMON_RUNTIME_GPU_GPU_BFC_ALLOCATOR_H_

#include <memory>
#include <string>

#include "tensorflow/core/framework/allocator.h"
#include "../../../core/framework/allocator.h"

// clang-format off
namespace tensorflow_cpy {
namespace tensorflow {
using namespace ::tensorflow;

// A GPU memory allocator that implements a 'best-fit with coalescing'
// algorithm.
Expand Down Expand Up @@ -36,5 +39,8 @@ class GPUBFCAllocator : public Allocator {
};

} // namespace tensorflow
} // namespace tensorflow_cpy
// clang-format on

#endif // TENSORFLOW_CORE_COMMON_RUNTIME_GPU_GPU_BFC_ALLOCATOR_H_

#endif // TENSORFLOW_CPY_CORE_COMMON_RUNTIME_GPU_GPU_BFC_ALLOCATOR_H_
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@

#ifndef TENSORFLOW_CORE_COMMON_RUNTIME_GPU_GPU_INIT_H_
#define TENSORFLOW_CORE_COMMON_RUNTIME_GPU_GPU_INIT_H_
#ifndef TENSORFLOW_CPY_CORE_COMMON_RUNTIME_GPU_GPU_INIT_H_
#define TENSORFLOW_CPY_CORE_COMMON_RUNTIME_GPU_GPU_INIT_H_

#include <string>

#include "tensorflow/core/platform/status.h"
#include "../../../core/platform/status.h"

// clang-format off
namespace tensorflow_cpy {
namespace stream_executor {
class Platform;
} // namespace stream_executor
} // namespace tensorflow_cpy
// clang-format on

// clang-format off
namespace tensorflow_cpy {
namespace tensorflow {
using namespace ::tensorflow;

// Initializes the GPU platform and returns OK if the GPU
// platform could be initialized.
Expand All @@ -28,5 +35,8 @@ stream_executor::Platform* GPUMachineManager();
std::string GpuPlatformName();

} // namespace tensorflow
} // namespace tensorflow_cpy
// clang-format on

#endif // TENSORFLOW_CORE_COMMON_RUNTIME_GPU_GPU_INIT_H_

#endif // TENSORFLOW_CPY_CORE_COMMON_RUNTIME_GPU_GPU_INIT_H_
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#ifndef TENSORFLOW_CORE_FRAMEWORK_ALLOCATOR_H_
#define TENSORFLOW_CORE_FRAMEWORK_ALLOCATOR_H_
#ifndef TENSORFLOW_CPY_CORE_FRAMEWORK_ALLOCATOR_H_
#define TENSORFLOW_CPY_CORE_FRAMEWORK_ALLOCATOR_H_

#include <stdlib.h>

#include <functional>
#include <optional>

#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/platform/macros.h"
#include "../../core/platform/logging.h"
#include "../../core/platform/macros.h"

// clang-format off
namespace tensorflow_cpy {
namespace tensorflow {
using namespace ::tensorflow;

// Runtime statistics collected by an allocator. Exactly the same as
// stream_executor::AllocatorStats, but independently defined to preserve the
Expand Down Expand Up @@ -221,5 +224,8 @@ class SubAllocator {
};

} // namespace tensorflow
} // namespace tensorflow_cpy
// clang-format on

#endif // TENSORFLOW_CORE_FRAMEWORK_ALLOCATOR_H_

#endif // TENSORFLOW_CPY_CORE_FRAMEWORK_ALLOCATOR_H_
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
// * Task numbers are within the specified replica, so there are as
// many "task zeros" as replicas.

#ifndef TENSORFLOW_CORE_FRAMEWORK_DEVICE_H_
#define TENSORFLOW_CORE_FRAMEWORK_DEVICE_H_
#ifndef TENSORFLOW_CPY_CORE_FRAMEWORK_DEVICE_H_
#define TENSORFLOW_CPY_CORE_FRAMEWORK_DEVICE_H_

#include <string>

#include "tensorflow/core/framework/allocator.h"
#include "tensorflow/core/framework/device_attributes.pb.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/status.h"
#include <tensorflow/core/framework/device_attributes.pb.h>
#include "../../core/framework/allocator.h"
#include "../../core/platform/env.h"
#include "../../core/platform/status.h"

// clang-format off
namespace tensorflow_cpy {
namespace tensorflow {
using namespace ::tensorflow;
class DeviceBase {
public:
explicit DeviceBase(Env* env) : env_(env) {}
Expand Down Expand Up @@ -85,5 +88,8 @@ class Device : public DeviceBase {
};

} // namespace tensorflow
} // namespace tensorflow_cpy
// clang-format on

#endif // TENSORFLOW_CORE_FRAMEWORK_DEVICE_H_

#endif // TENSORFLOW_CPY_CORE_FRAMEWORK_DEVICE_H_
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#ifndef TENSORFLOW_CORE_FRAMEWORK_OP_H_
#define TENSORFLOW_CORE_FRAMEWORK_OP_H_
#ifndef TENSORFLOW_CPY_CORE_FRAMEWORK_OP_H_
#define TENSORFLOW_CPY_CORE_FRAMEWORK_OP_H_

#include "tensorflow/core/platform/status.h"
#include "../../core/platform/status.h"

// clang-format off
namespace tensorflow_cpy {
namespace tensorflow {
using namespace ::tensorflow;

// The standard implementation of OpRegistryInterface, along with a
// global singleton used for registering ops via the REGISTER
Expand Down Expand Up @@ -48,5 +51,8 @@ class OpRegistry {
};

} // namespace tensorflow
} // namespace tensorflow_cpy
// clang-format on

#endif // TENSORFLOW_CORE_FRAMEWORK_OP_H_

#endif // TENSORFLOW_CPY_CORE_FRAMEWORK_OP_H_
Loading

0 comments on commit 52be440

Please sign in to comment.