Skip to content

Commit

Permalink
Use flatbuffer of alternate namespace (pytorch#82952)
Browse files Browse the repository at this point in the history
Summary: Minimal change to make use of flatbuffer with fbsource namespace.

Test Plan: existing unit tests

Differential Revision: D38494999

Pull Request resolved: pytorch#82952
Approved by: https://github.com/cccclai
  • Loading branch information
qihqi authored and pytorchmergebot committed Aug 9, 2022
1 parent b4b60c2 commit f953356
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
10 changes: 4 additions & 6 deletions buckbuild.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ THIRD_PARTY_LIBS = {
"XNNPACK": ["//xplat/third-party/XNNPACK:XNNPACK", "//third_party:XNNPACK"],
"clog": ["//xplat/third-party/clog:clog", "//third_party:clog"],
"cpuinfo": ["//third-party/cpuinfo:cpuinfo", "//third_party:cpuinfo"],
"flatbuffers-api": ["//third-party/flatbuffers:flatbuffers-api", "//third_party:flatbuffers-api"],
"flatc": ["//third-party/flatbuffers:flatc", "//third_party:flatc"],
"flatbuffers-api": ["//third-party/flatbuffers/fbsource_namespace:flatbuffers-api", "//third_party:flatbuffers-api"],
"flatc": ["//third-party/flatbuffers/fbsource_namespace:flatc", "//third_party:flatc"],
"fmt": ["//third-party/fmt:fmt", "//third_party:fmt"],
"glog": ["//third-party/glog:glog", "//third_party:glog"],
"gmock": ["//xplat/third-party/gmock:gtest", "//third_party:gmock"],
Expand Down Expand Up @@ -1497,8 +1497,6 @@ def define_buck_targets(
# "torch/csrc/jit/mobile/compatibility/runtime_compatibility.cpp",
# "torch/csrc/jit/serialization/unpickler.cpp",
"torch/csrc/jit/mobile/compatibility/model_compatibility.cpp",
"torch/csrc/jit/serialization/pickle.cpp",
"torch/csrc/jit/serialization/pickler.cpp",
],
header_namespace = "",
exported_headers = [
Expand Down Expand Up @@ -1714,7 +1712,7 @@ def define_buck_targets(
"-fexceptions",
"-frtti",
"-Wno-deprecated-declarations",
],
] + (["-DFB_XPLAT_BUILD"] if not IS_OSS else []),
visibility = ["PUBLIC"],
deps = [
":torch_mobile_module",
Expand Down Expand Up @@ -1743,7 +1741,7 @@ def define_buck_targets(
# Need this otherwise USE_KINETO is undefed
# for mobile
"-DEDGE_PROFILER_USE_KINETO",
],
] + (["-DFB_XPLAT_BUILD"] if not IS_OSS else []),
extra_flags = {
"fbandroid_compiler_flags": ["-frtti"],
},
Expand Down
3 changes: 3 additions & 0 deletions test/cpp/jit/test_flatbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,9 @@ TEST(FlatbufferUpgraderTest, DivScalarInplaceIntV2) {
namespace torch {
namespace jit {

#if defined(FBCODE_CAFFE2) or defined(FB_XPLAT_BUILD)
namespace flatbuffers = flatbuffers_fbsource;
#endif
/**
* An Allocator that can only deallocate (using delete []), counting
* the number of times that it has been asked to deallocate.
Expand Down
5 changes: 5 additions & 0 deletions torch/csrc/jit/mobile/flatbuffer_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
#include <cstdlib>
#endif

#if defined(FBCODE_CAFFE2) or defined(FB_XPLAT_BUILD)
namespace flatbuffers = flatbuffers_fbsource;
#define FLATBUFFERS_MAX_ALIGNMENT FLATBUFFERS_FBSOURCE_MAX_ALIGNMENT
#endif

namespace torch {
namespace jit {

Expand Down
5 changes: 5 additions & 0 deletions torch/csrc/jit/serialization/flatbuffer_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#include <torch/csrc/jit/serialization/export.h>
#include <torch/csrc/jit/serialization/mobile_bytecode_generated.h> // NOLINT

#if defined(FBCODE_CAFFE2) or defined(FB_XPLAT_BUILD)
namespace flatbuffers = flatbuffers_fbsource;
#define FLATBUFFERS_MAX_ALIGNMENT FLATBUFFERS_FBSOURCE_MAX_ALIGNMENT
#endif

namespace torch {
namespace jit {

Expand Down

0 comments on commit f953356

Please sign in to comment.