Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into port_python3_syntax
commit
a58dd3e557
@ -0,0 +1,40 @@
|
|||||||
|
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Licensed 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 KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
#include "paddle/fluid/framework/data_type.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "paddle/fluid/framework/tensor.h"
|
||||||
|
|
||||||
|
TEST(DataType, float16) {
|
||||||
|
using paddle::framework::Tensor;
|
||||||
|
using paddle::platform::CPUPlace;
|
||||||
|
using paddle::platform::float16;
|
||||||
|
namespace f = paddle::framework;
|
||||||
|
f::proto::VarType::Type dtype = f::proto::VarType::FP16;
|
||||||
|
|
||||||
|
Tensor tensor;
|
||||||
|
CPUPlace cpu;
|
||||||
|
tensor.mutable_data(cpu, f::ToTypeIndex(dtype));
|
||||||
|
|
||||||
|
// test fp16 tensor
|
||||||
|
EXPECT_EQ(tensor.type(), std::type_index(typeid(float16)));
|
||||||
|
|
||||||
|
// test fp16 size
|
||||||
|
EXPECT_EQ(f::SizeOfType(f::ToTypeIndex(dtype)), 2u);
|
||||||
|
|
||||||
|
// test debug info
|
||||||
|
std::string type = "float16";
|
||||||
|
EXPECT_STREQ(f::DataTypeToString(dtype).c_str(), type.c_str());
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Licensed 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 KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "paddle/fluid/platform/enforce.h"
|
||||||
|
|
||||||
|
namespace paddle {
|
||||||
|
namespace framework {
|
||||||
|
namespace details {
|
||||||
|
|
||||||
|
class ExceptionHolder {
|
||||||
|
public:
|
||||||
|
void Catch(const platform::EnforceNotMet& exp) {
|
||||||
|
std::lock_guard<std::mutex> lock(mu_);
|
||||||
|
exception_.reset(new platform::EnforceNotMet(exp));
|
||||||
|
type_ = kEnforceNotMet;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Catch(const platform::EOFException& exp) {
|
||||||
|
std::lock_guard<std::mutex> lock(mu_);
|
||||||
|
// EOFException will not cover up existing EnforceNotMet.
|
||||||
|
if (exception_.get() == nullptr) {
|
||||||
|
exception_.reset(new platform::EOFException(exp));
|
||||||
|
type_ = kEOF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ExceptionCatched() const {
|
||||||
|
std::lock_guard<std::mutex> lock(mu_);
|
||||||
|
return exception_.get() != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Throw() {
|
||||||
|
std::lock_guard<std::mutex> lock(mu_);
|
||||||
|
switch (type_) {
|
||||||
|
case kNone:
|
||||||
|
break;
|
||||||
|
case kEnforceNotMet: {
|
||||||
|
auto e = *static_cast<platform::EnforceNotMet*>(exception_.get());
|
||||||
|
throw e;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case kEOF: {
|
||||||
|
auto e = *static_cast<platform::EOFException*>(exception_.get());
|
||||||
|
throw e;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
LOG(FATAL) << "Unknown exception.";
|
||||||
|
}
|
||||||
|
exception_.reset();
|
||||||
|
type_ = kNone;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clear() {
|
||||||
|
std::lock_guard<std::mutex> lock(mu_);
|
||||||
|
exception_.reset();
|
||||||
|
type_ = kNone;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum ExceptionType { kNone, kEnforceNotMet, kEOF };
|
||||||
|
ExceptionType type_{kNone};
|
||||||
|
|
||||||
|
std::unique_ptr<std::exception> exception_;
|
||||||
|
mutable std::mutex mu_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace details
|
||||||
|
} // namespace framework
|
||||||
|
} // namespace paddle
|
@ -0,0 +1,33 @@
|
|||||||
|
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Licensed 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 KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file implements analysizer -- an executation help to analyze and
|
||||||
|
* optimize trained model.
|
||||||
|
*/
|
||||||
|
#include "paddle/fluid/inference/analysis/analyzer.h"
|
||||||
|
#include <gflags/gflags.h>
|
||||||
|
#include <glog/logging.h>
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
google::ParseCommandLineFlags(&argc, &argv, true);
|
||||||
|
using paddle::inference::analysis::Analyzer;
|
||||||
|
using paddle::inference::analysis::Argument;
|
||||||
|
|
||||||
|
Argument argument;
|
||||||
|
Analyzer analyzer;
|
||||||
|
analyzer.Run(&argument);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue