Skip to content

Commit

Permalink
Merged master:71059257bd4 into amd-gfx:be729eb2277
Browse files Browse the repository at this point in the history
Local branch amd-gfx be729eb Merged master:6700f4b9fe6 into amd-gfx:7dd816f37b8
Remote branch master 7105925 [llvm][NFC] TensorSpec abstraction for ML evaluator
  • Loading branch information
Sw authored and Sw committed Jul 29, 2020
2 parents be729eb + 7105925 commit 0285300
Show file tree
Hide file tree
Showing 62 changed files with 217 additions and 304 deletions.
5 changes: 2 additions & 3 deletions clang/lib/Driver/ToolChains/Darwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,10 +1062,9 @@ void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
DarwinLibName += Component;
if (!(Opts & RLO_IsEmbedded))
DarwinLibName += "_";
DarwinLibName += getOSLibraryNameSuffix();
} else
DarwinLibName += getOSLibraryNameSuffix(true);
}

DarwinLibName += getOSLibraryNameSuffix();
DarwinLibName += IsShared ? "_dynamic.dylib" : ".a";
SmallString<128> Dir(getDriver().ResourceDir);
llvm::sys::path::append(
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGen/Inputs/thinlto_expect1.proftext
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:ir
foo
# Func Hash:
784007059655560962
25571299074
# Num Counters:
2
# Counter Values:
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CodeGen/Inputs/thinlto_expect2.proftext
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:csir
foo
# Func Hash:
784007059655560962
25571299074
# Num Counters:
2
# Counter Values:
Expand All @@ -11,7 +11,7 @@ foo

foo
# Func Hash:
1936928564262407938
1152921530178146050
# Num Counters:
2
# Counter Values:
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenCXX/Inputs/profile-remap.proftext
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:ir
_ZN3Foo8functionENS_1XE
146835647075900052
29667547796
2
10
90
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenCXX/Inputs/profile-remap_entry.proftext
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:ir
:entry_first
_ZN3Foo8functionENS_1XE
146835647075900052
29667547796
2
100
90
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion clang/test/Driver/darwin-ld.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
// RUN: FileCheck -check-prefix=LINK_IOSSIM_PROFILE %s < %t.log
// LINK_IOSSIM_PROFILE: {{ld(.exe)?"}}
// LINK_IOSSIM_PROFILE: libclang_rt.profile_iossim.a
// LINK_IOSSIM_PROFILE: libclang_rt.ios.a
// LINK_IOSSIM_PROFILE: libclang_rt.iossim.a

// RUN: %clang -target arm64-apple-tvos8.3 -mlinker-version=400 -mtvos-version-min=8.3 -resource-dir=%S/Inputs/resource_dir -### %t.o 2> %t.log
// RUN: FileCheck -check-prefix=LINK_TVOS_ARM64 %s < %t.log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:ir
main
# Func Hash:
1063705162469825436
34137660316
# Num Counters:
2
# Counter Values:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:entry_first
main
# Func Hash:
1063705162469825436
34137660316
# Num Counters:
2
# Counter Values:
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/cmake/Modules/AddCompilerRT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ endfunction()
function(add_asm_sources output)
set(${output} ${ARGN} PARENT_SCOPE)
# Xcode will try to compile asm files as C ('clang -x c'), and that will fail.
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
if (${CMAKE_GENERATOR} STREQUAL "Xcode")
enable_language(ASM)
else()
# Pass ASM file directly to the C++ compiler.
Expand Down
24 changes: 15 additions & 9 deletions compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ macro(darwin_add_builtin_library name suffix)
endforeach(cflag)
endif()

if ("${LIB_OS}" MATCHES ".*sim$")
# Pass an explicit -simulator environment to the -target option to ensure
# that we don't rely on the architecture to infer whether we're building
# for the simulator.
string(REGEX REPLACE "sim" "" base_os "${LIB_OS}")
list(APPEND builtin_cflags
-target "${LIB_ARCH}-apple-${base_os}${DARWIN_${LIBOS}_BUILTIN_MIN_VER}-simulator")
endif()

set_target_compile_flags(${libname}
${sysroot_flag}
${DARWIN_${LIB_OS}_BUILTIN_MIN_VER_FLAG}
Expand Down Expand Up @@ -449,16 +458,13 @@ macro(darwin_add_builtin_libraries)
endif()
endforeach()

# We put the x86 sim slices into the archives for their base OS
foreach (os ${ARGN})
if(NOT ${os} MATCHES ".*sim$")
darwin_lipo_libs(clang_rt.${os}
PARENT_TARGET builtins
LIPO_FLAGS ${${os}_builtins_lipo_flags} ${${os}sim_builtins_lipo_flags}
DEPENDS ${${os}_builtins_libs} ${${os}sim_builtins_libs}
OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
endif()
darwin_lipo_libs(clang_rt.${os}
PARENT_TARGET builtins
LIPO_FLAGS ${${os}_builtins_lipo_flags}
DEPENDS ${${os}_builtins_libs}
OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
endforeach()
darwin_add_embedded_builtin_libraries()
endmacro()
Expand Down
2 changes: 0 additions & 2 deletions compiler-rt/lib/dfsan/done_abilist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ fun:dfsan_set_write_callback=uninstrumented
fun:dfsan_set_write_callback=custom
fun:dfsan_flush=uninstrumented
fun:dfsan_flush=discard
fun:dfsan_use_fast16labels=uninstrumented
fun:dfsan_use_fast16labels=discard

###############################################################################
# glibc
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/profile/Linux/instrprof-value-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) {

// CHECK: Counters:
// CHECK: main:
// CHECK: Hash: 0x0a9bd81e87ab6e87
// CHECK: Hash: 0x00030012a7ab6e87
// CHECK: Counters: 6
// CHECK: Indirect Call Site Count: 3
// CHECK: Number of Memory Intrinsics Calls: 3
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ add_dependencies(check-lldb-reproducers check-lldb-reproducers-capture)
if(LLDB_BUILT_STANDALONE)
# This has to happen *AFTER* add_lit_testsuite.
if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
# LLVM's make_paths_relative uses Python3_EXECUTABLE which isn't set in a
# standalone LLDB build.
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)
endif()
endif()
72 changes: 49 additions & 23 deletions llvm/include/llvm/Analysis/Utils/TFUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,43 @@ namespace llvm {
class TFModelEvaluatorImpl;
class EvaluationResultImpl;

/// TensorSpec encapsulates the specification of a tensor: its dimensions, or
/// "shape" (row-major), its type (see TensorSpec::getDataType specializations
/// for supported types), its name and port (see "TensorFlow: Large-Scale
/// Machine Learning on Heterogeneous Distributed Systems", section 4.2, para 2:
/// https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/45166.pdf)
///
/// TensorSpec is used to set up a TFModelEvaluator by describing the expected
/// inputs and outputs.
class TensorSpec final {
public:
template <typename T>
static TensorSpec createSpec(const std::string &Name,
const std::vector<int64_t> &Shape,
int Port = 0) {
return TensorSpec(Name, Port, getDataType<T>(), Shape);
}

const std::string &name() const { return Name; }
int port() const { return Port; }
int typeIndex() const { return TypeIndex; }
const std::vector<int64_t> &shape() const { return Shape; }

private:
TensorSpec(const std::string &Name, int Port, int TypeIndex,
const std::vector<int64_t> &Shape)
: Name(Name), Port(Port), TypeIndex(TypeIndex), Shape(Shape) {}

template <typename T> static int getDataType() {
llvm_unreachable("Undefined tensor type");
}

std::string Name;
int Port = 0;
int TypeIndex = 0;
std::vector<int64_t> Shape;
};

class TFModelEvaluator final {
public:
/// The result of a model evaluation. Handles the lifetime of the output
Expand All @@ -60,8 +97,8 @@ class TFModelEvaluator final {
};

TFModelEvaluator(StringRef SavedModelPath,
const std::vector<std::string> &InputNames,
const std::vector<std::string> &OutputNames,
const std::vector<TensorSpec> &InputSpecs,
const std::vector<TensorSpec> &OutputSpecs,
const char *Tags = "serve");
~TFModelEvaluator();
TFModelEvaluator(const TFModelEvaluator &) = delete;
Expand All @@ -82,32 +119,21 @@ class TFModelEvaluator final {
/// otherwise.
bool isValid() const { return !!Impl; }

/// Initialize the input at Index as a tensor of the given type and
/// dimensions.
template <typename T>
void initInput(size_t Index, const std::vector<int64_t> &Dimensions) {
return initInput(Index, getModelTypeIndex<T>(), Dimensions);
}

private:
void *getUntypedInput(size_t Index);
template <typename T> int getModelTypeIndex();
void initInput(size_t Index, int TypeIndex,
const std::vector<int64_t> &Dimensions);

std::unique_ptr<TFModelEvaluatorImpl> Impl;
};

template <> int TFModelEvaluator::getModelTypeIndex<float>();
template <> int TFModelEvaluator::getModelTypeIndex<double>();
template <> int TFModelEvaluator::getModelTypeIndex<int8_t>();
template <> int TFModelEvaluator::getModelTypeIndex<uint8_t>();
template <> int TFModelEvaluator::getModelTypeIndex<int16_t>();
template <> int TFModelEvaluator::getModelTypeIndex<uint16_t>();
template <> int TFModelEvaluator::getModelTypeIndex<int32_t>();
template <> int TFModelEvaluator::getModelTypeIndex<uint32_t>();
template <> int TFModelEvaluator::getModelTypeIndex<int64_t>();
template <> int TFModelEvaluator::getModelTypeIndex<uint64_t>();
template <> int TensorSpec::getDataType<float>();
template <> int TensorSpec::getDataType<double>();
template <> int TensorSpec::getDataType<int8_t>();
template <> int TensorSpec::getDataType<uint8_t>();
template <> int TensorSpec::getDataType<int16_t>();
template <> int TensorSpec::getDataType<uint16_t>();
template <> int TensorSpec::getDataType<int32_t>();
template <> int TensorSpec::getDataType<uint32_t>();
template <> int TensorSpec::getDataType<int64_t>();
template <> int TensorSpec::getDataType<uint64_t>();

} // namespace llvm

Expand Down
60 changes: 13 additions & 47 deletions llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,35 +298,12 @@ class ModelUnderTrainingRunner final : public MLModelRunner {
private:
std::unique_ptr<TFModelEvaluator> Evaluator;

// The training framework needs some additional features, that just need to
// be set to 0.
struct TensorSpec {
std::string Name;
std::function<void(TFModelEvaluator *, size_t Index,
const std::vector<int64_t> &Dim)>
Initializer;
};

// The training framework needs some additional features.
const std::vector<TensorSpec> TrainingOnlyFeatures{
{"inlining_default",
[](TFModelEvaluator *Evaluator, size_t Index,
const std::vector<int64_t> &Dim) {
Evaluator->initInput<int64_t>(Index, Dim);
}},
{"discount",
[](TFModelEvaluator *Evaluator, size_t Index,
const std::vector<int64_t> &Dim) {
Evaluator->initInput<float>(Index, Dim);
}},
{"reward",
[](TFModelEvaluator *Evaluator, size_t Index,
const std::vector<int64_t> &Dim) {
Evaluator->initInput<float>(Index, Dim);
}},
{"step_type", [](TFModelEvaluator *Evaluator, size_t Index,
const std::vector<int64_t> &Dim) {
Evaluator->initInput<int32_t>(Index, Dim);
}}};
TensorSpec::createSpec<int64_t>(TFFeedPrefix + "inlining_default", {1}),
TensorSpec::createSpec<float>(TFFeedPrefix + "discount", {1}),
TensorSpec::createSpec<float>(TFFeedPrefix + "reward", {1}),
TensorSpec::createSpec<int32_t>(TFFeedPrefix + "step_type", {1})};
};
} // namespace

Expand Down Expand Up @@ -409,33 +386,22 @@ size_t DevelopmentModeMLInlineAdvisor::getTotalSizeEstimate() {
ModelUnderTrainingRunner::ModelUnderTrainingRunner(LLVMContext &Ctx,
const std::string &ModelPath)
: MLModelRunner(Ctx) {
std::vector<std::string> InputNames;
std::vector<std::string> OutputNames;
std::vector<TensorSpec> InputSpecs;
std::vector<TensorSpec> OutputSpecs;
for (size_t I = 0; I < NumberOfFeatures; ++I)
InputNames.push_back(TFFeedPrefix + FeatureNameMap[I]);
for (size_t I = 0; I < TrainingOnlyFeatures.size(); ++I)
InputNames.push_back(TFFeedPrefix + TrainingOnlyFeatures[I].Name);
OutputNames.push_back(TFDecisionName);
InputSpecs.push_back(
TensorSpec::createSpec<int64_t>(TFFeedPrefix + FeatureNameMap[I], {1}));
InputSpecs.insert(InputSpecs.end(), TrainingOnlyFeatures.begin(),
TrainingOnlyFeatures.end());
OutputSpecs.push_back(TensorSpec::createSpec<int64_t>(TFDecisionName, {1}));

Evaluator =
std::make_unique<TFModelEvaluator>(ModelPath, InputNames, OutputNames);
std::make_unique<TFModelEvaluator>(ModelPath, InputSpecs, OutputSpecs);
if (!Evaluator || !Evaluator->isValid()) {
Ctx.emitError("Failed to create inliner saved model evaluator");
Evaluator.reset();
return;
}

static const std::vector<int64_t> Dim{1};

size_t InputIndex = 0;
for (; InputIndex < NumberOfFeatures; ++InputIndex) {
Evaluator->initInput<int64_t>(InputIndex, Dim);
}

for (; InputIndex < InputNames.size(); ++InputIndex) {
TrainingOnlyFeatures[InputIndex - NumberOfFeatures].Initializer(
Evaluator.get(), InputIndex, Dim);
}
}

bool ModelUnderTrainingRunner::run() {
Expand Down
15 changes: 7 additions & 8 deletions llvm/lib/Analysis/InlineSizeEstimatorAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,18 @@ InlineSizeEstimatorAnalysis::InlineSizeEstimatorAnalysis() {
if (!isEvaluatorRequested()) {
return;
}
std::vector<std::string> InputNames{"serving_default_input_1"};
std::vector<std::string> OutputName{"StatefulPartitionedCall"};
std::vector<TensorSpec> InputSpecs{TensorSpec::createSpec<int32_t>(
"serving_default_input_1",
{1, static_cast<int64_t>(
IRToNativeSizeLearning::FunctionFeatures::FeatureCount)})};
std::vector<TensorSpec> OutputSpecs{
TensorSpec::createSpec<float>("StatefulPartitionedCall", {1})};
Evaluator = std::make_unique<TFModelEvaluator>(
TFIR2NativeModelPath.getValue().c_str(), InputNames, OutputName);
TFIR2NativeModelPath.getValue().c_str(), InputSpecs, OutputSpecs);
if (!Evaluator || !Evaluator->isValid()) {
Evaluator.reset();
return;
}
static const std::vector<int64_t> Dim{
1, static_cast<int64_t>(
IRToNativeSizeLearning::FunctionFeatures::FeatureCount)};

Evaluator->initInput<int32_t>(0, Dim);
}

InlineSizeEstimatorAnalysis::Result
Expand Down
Loading

0 comments on commit 0285300

Please sign in to comment.