Skip to content

Commit

Permalink
Update from Facebook (pytorch#8887)
Browse files Browse the repository at this point in the history
* add opencl + fpga context

adds an opencl context inside caffe2/fb which can be used for fpga access

* [Caffe2] Force tensor inference checks to be triggered during testing

We've started to rely on TensorInference functions more for different analysis.  This diff ensures that the TensorInference function's result matches what is expected from the definition of the operator.

* Enable building //caffe2:torch with @mode/opt

In @mode/opt, python runs out of a PAR, which breaks a lot of
assumptions in the code about where templates/ folders live relative
to __file__. Rather than introduce hacks with parutil, I simply turn
template_path into a parameter for all the relevant functions and
thread it through from the top level.

* [Caffe2] Fix cost models for DotProduct and Div.  Update Tensor Inference for dot product

As title.  DotProduct states that output is a 1-D tensor (https://caffe2.ai/docs/operators-catalogue.html#dotproduct) though code suggests it is either 0- or 1-D depending on inputs.  TensorInference defined to support implementation.

* [SG-MoE] Add an option to make the experts NOT as components

* [nomnigraph] Rename and fixup convertToNeuralNetOperator API

This will make things a bit cleaner

* no longer symlink THNN.h and THCUNN.h

* forced decoder network (onnx export)

Closes pytorch/translate#95

Add networks in ensemble_export.py to create a forced decoding network from PyTorch NMT checkpoints. This network takes an arbitrary numberized (source, target) pair and returns the model score for the translation, including penalties.

Vocabulary reduction networks are also supported, but note that target indices which are not in the possible_translation_tokens generated for the source input will be trea

* Revert schema change to fix production models

Revert schema change to fix production models

* MockLogDeviceReader - rebase on FIX

# Goal

1), Build a make_mock_log_device_reader using make_mock_reader

2), Replace the real log_device_reader here: https://fburl.com/raihwf1p

# Log by D8151734

Real log_device_reader:
```
I0529 20:29:05.373108 954994 tensor.h:839] Tensor print_net/log of type std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >. Dims: (): read_net/ParseOpenTrainingRow:0
I0529 20:29:05.373244 954994 tensor.h:839] Tensor read_net/ParseOpenTrainin

* [C2/D2][1/n]: Nonnegative-Constrained Optimization -- log barrier

implement log barrier as a regularization method

* Add teacher weight screening.

Add teacher weight sceening according to teacher labels. If teacher label is zero, we do not use the distill loss in the objective function.

* Add NormalizerContext

See task for more detail. This implementation is a copy of what exists for RegularizerContext except for how the parameters are defined in the model_definition thrift file.

I'll try an alternative implementation which overrides the default arguments of functions instead like for argscopes in tensorflow.

https://github.com/pytorch/pytorch/compare/master...MaximeBoucher:update-from-facebook-0939578c068c?expand=1

* Adding cosine similarity option in dot processor

Add pairwise cosine similarity option in dot product.
Add an option to concate dot product and cosine similarity.
Add test cases.

* [nomnigraph][redo] Concat elim for sparseNN

Same as D7962948, which was reverted because Operator Schema was not
defined

* [pytorch] Revert pytorch#7918 'Release GIL when copying to shared memory', breaks ASAN

Revert this pytorch diff that breaks ASAN when running Filament in dev mode; in opt mode it gives "bad file descriptor" errors. Looks like a race when copying tensors to shared memory in multiple mp.Queue's (which spawn separate threads).

https://github.com/pytorch/pytorch/pull/7918/files

* [nomnigraph][mobile] Enable nomnigraph by default, use -Oz on nomnigraph related code to reduce code size

enables nomnigraph and reduces codesize

* [Warmup] Allow both offline incremental training and online training

Change plan name on saving side and reading side to support both training type

This diff depends on D8128530 and D8168651.

* Revert D7802642: [Warmup] Allow both offline incremental training and online training

This reverts commit afc213cf9b36cecf75333a788391c4d09f4afccc

@bypass-lint

An infra SEV is better than not reverting this diff.
If you copy this password, see you in SEV Review!
@cause_a_sev_many_files

* Add legacy grad logic to fix div op on old graphs.

Add legacy grad logic to fix div op on old graphs.

* Correctly propagate operator failures

Propagate errors from operators that throw exceptions and return false

* Revert D8374829: [caffe2][nomnigraph][redo] Concat elim for sparseNN

This reverts commit 6dda028c463e54bb5c32188bbbe9202107e188a5

@bypass-lint

An infra SEV is better than not reverting this diff.
If you copy this password, see you in SEV Review!
@cause_a_sev_many_files

* [Caffe2] Added extra_info to core.DeviceOption(), enforced extra_info to be inherited in scope.DeviceScope

extra_info is a newly defined field in DeviceOption proto. This diff added extra_info to the core.DeviceOption().  And, In scope.DeviceScope(), this diff enforce the new scope to inherit the extra_info from old scope.

* [opt] hgdirsync wasn't enabled, merge diverged code

Here's the damage, P59732616 basically xplat was left behind but had
the change from assert to CAFFE_ENFORCE

* OMP parallelism over RoIs for RoIAlign op

Simpler to parallelize over RoIs. Shouldn't affect other uses as it relies on
the number of OMP threads set during startup.

PR: pytorch#8562

* Use int64_t for shape in FillOps

to avoid overflow of int32

* Implement Rotated RoIAlign op

Based on Rotated RPNs as explained in https://arxiv.org/abs/1703.01086.
The idea is simple - orientation/angle is added as an RPN
anchor parameter and then the angle is further regressed similar to bbox
coords. There are some additional changes related to NMS and IoU, but besides
that it's a direct extension to Faster-RCNN. Further details in https://fb.quip.com/sZHlA1iMfWPZ.

RoIs are represented in [center_x, center_y, width, height, angle] format.
`angle` repre

* Rotated RoIAlign op CUDA forward implementation

CUDA forward impl for D8415490

* RoIAlignRotated op CUDA backward pass implementation

TSIA

* All remaining fixes to eliminate process_github.sh

Most of this diff has already been reviewed separately, except for the parts relating to _thnn/utils.py and _utils._internal.py

remove skipIf(True, 'Fbcode') line from process_github.sh

replace sed of cpp file with #ifdef to control cudnnDestroy use

undo sync-time deletion of .gitattributes, remove process_github.sh

switch to using _utils._internal rather than try-import-except

This diff also fixes the open-source bug where rebuilds have

* Back out "Revert D7802642: [Warmup] Allow both offline incremental training and online training"

Original commit changeset: 7707d2efe60e The original diff is backout becuase the online trainer package is backed out. This code would only work with new online trainer package

* [easy] improve error log in adagrad op

as title

* re-allow use of thnn_h_path

This fixes cffi usage in OSS

* [4/4] [tum] paralyzing layerNorm for GPU full sync

as title

* add compile=False to pytorch tests, remove hack with pyc

* Add shape and type inference for RowWiseArgMax operator

See title

* Revert D8515341: Back out "Revert D7802642: [Warmup] Allow both offline incremental training and online training"

This reverts commit 78167eeef0af16b60f72c82f9dcdda9b41b4dcbd

@bypass-lint

An infra SEV is better than not reverting this diff.
If you copy this password, see you in SEV Review!
@cause_a_sev_many_files

* [fix-flaky-test] mock_hive_reader_test flaky, because GlobalCounter collects local counts intervally

# Problem

`MockHiveReader` uses `GlobalCounter` to limit `max_examples`.

GlobalCounter on server node collect local counts from worker nodes every 1 sec.

This 1 sec delay makes it impossible to limit exactly to the `max_examples`, it will definitely exceed `max_examples`.

# Plan

Given,
```
Expected num_examples = max_examples + num_examples/sec (Read Speed) x 1 sec (GlobalCounter Sync Int

* [Caffe2] Fix FCGradient cost inference.  Prevent overflow in cost inference

FCGradient missed a factor 2 in the `num_outputs == 3` case.  Overflow was occurring with flop calculation for FC.  Changed types to `uint64_t` to prevent future problems.

* Fix binary ops with empty inputs

Fix binary ops with empty inputs

* Support the filling of input blob with provided data

as title for Biz Integrity case

* Back out "Revert D8515341: Back out "Revert D7802642: [Warmup] Allow both offline incremental training and online training""

Original commit changeset: 30c55dd38816 Original diff is reverted due to introducing bad integration test. Fixed the integration test.

* [c2][easy] improve pack ops error loggings

as desc.

* Add ShapeTypeInference for LpNorm operator

As desc

* Shard test_nn to reduce runtime for each test target

Closes pytorch#8793

The current test_nn would time out and be disabled in GreenWarden, and we need to have an option to split it up in order to pass the stress test. Right now GreenWarden roughly allows running 100 test cases in test_nn before timing out, and here we have an option to divide test_nn into 30 shards (with ~40 tests in each shard) to allow for some test suite growth in the future.

* Change default caffe2_streams_per_gpu to 1

* Remove IN_SANDCASTLE from common.py and test_nn.py

We prefer to disable the failing tests through Sandcastle UI instead.

* Add a new class for an updated prof_dag.proto

This diff contains:
- An updated prof_dag.proto that contains blob profiles.
- A class to deserialize this information (serialization is in a follow up diff)
- Update to separate profiling information from NeuralNet (and use it as part of the class above).
- Unit tests

* Lambdarank for SparseNN

This diff adds a lambda_rank_layer for SparseNN.
 changes include
1) Adds support for multi sessions in c2 op
2) Adds support for two different loss functions in c2 op
3) Unit tests for op

* Revert D8586950: Back out "Revert D8515341: Back out "Revert D7802642: [Warmup] Allow both offline incremental training and online training""

This reverts commit 012220ed63eccc35659a57b31d16a3625da6317b

@bypass-lint

An infra SEV is better than not reverting this diff.
If you copy this password, see you in SEV Review!
@cause_a_sev_many_files

* [easy] A few fixups to multithread predictor benchmark

(1) support perf on T6 server
(2) remove dead code

* fix a bug about the map size

as title

* Fix reduce sum on in-place case.

Fix reduce sum on in-place case.

* [Warmup] Reland reverted diff Allow both offline incremental training and online training

Closes pytorch#8827

fix net transform integration test. Allow offline and online trainer to coexist D7802642.

* Add StoreHandlerNotAvailableException

Add an exception for a store that is not available or has been
deleted.

* Use exception handling for fault tolerance, missing KV store

Remove status blobs to communication ops so that exceptions propagate on
failure.

* [C2/D2][2/n]: Nonnegative-Constrained Optimization -- bounded grad proj

for simple bounded constrained optimization, incl non-negative box constraints.

* [GanH]: Adaptive Weighting with More Estimations

With implemented postivity optimization, we now learn adaptive weights with different
parameterizations.

This improves parameter estimation and training stability.

* Revert some changes for landing

* Remove AutoNoGIL in StorageSharing

* Temporarily disable net_tests

* Revert "[Caffe2] Force tensor inference checks to be triggered during testing"

This reverts commit 67ef05c22b2f71b4a489695384932f968384a2a4.

* Revert "Fix reduce sum on in-place case."

This reverts commit 6cb8a8e1b3db7b6d20941b0053e3f3836068eb64.

* Revert "Revert "Fix reduce sum on in-place case.""

This reverts commit 130a257.
  • Loading branch information
orionr authored Jun 26, 2018
1 parent 055f527 commit edb88b5
Show file tree
Hide file tree
Showing 128 changed files with 3,819 additions and 757 deletions.
41 changes: 38 additions & 3 deletions binaries/benchmark_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "observers/observer_config.h"
#include "observers/perf_observer.h"

using std::map;
using std::shared_ptr;
using std::string;
using std::unique_ptr;
Expand Down Expand Up @@ -91,6 +92,7 @@ void setOperatorEngine(caffe2::NetDef* net_def, const string& backend) {
void loadInput(
shared_ptr<caffe2::Workspace> workspace,
const bool run_on_gpu,
map<string, caffe2::TensorProtos>& tensor_protos_map,
const string& input,
const string& input_file,
const string& input_dims,
Expand All @@ -105,9 +107,11 @@ void loadInput(
input_files.size(),
"Input name and file should have the same number.");
for (int i = 0; i < input_names.size(); ++i) {
caffe2::BlobProto blob_proto;
CAFFE_ENFORCE(caffe2::ReadProtoFromFile(input_files[i], &blob_proto));
workspace->CreateBlob(input_names[i])->Deserialize(blob_proto);
caffe2::TensorProtos tensor_protos;
CAFFE_ENFORCE(
caffe2::ReadProtoFromFile(input_files[i], &tensor_protos));
workspace->CreateBlob(input_names[i]);
tensor_protos_map.insert(std::make_pair(input_names[i], tensor_protos));
}
} else if (input_dims.size() || input_type.size()) {
CAFFE_ENFORCE_GE(
Expand Down Expand Up @@ -176,9 +180,38 @@ void loadInput(
}
}

void fillInputBlob(
shared_ptr<caffe2::Workspace> workspace,
map<string, caffe2::TensorProtos>& tensor_protos_map,
int iteration) {
if (tensor_protos_map.empty()) {
return;
}

for (auto& tensor_kv : tensor_protos_map) {
caffe2::Blob* blob = workspace->GetBlob(tensor_kv.first);
if (blob == nullptr) {
blob = workspace->CreateBlob(tensor_kv.first);
}
// todo: support gpu and make this function a tempalte
int protos_size = tensor_kv.second.protos_size();
caffe2::TensorProto* tensor_proto =
tensor_kv.second.mutable_protos(iteration % protos_size);
caffe2::TensorCPU* tensor = blob->GetMutable<caffe2::TensorCPU>();
tensor->Resize(std::vector<caffe2::TIndex>());
if (tensor_proto->data_type() == caffe2::TensorProto::STRING) {
(tensor->mutable_data<std::string>())[0] = tensor_proto->string_data(0);
} else if (tensor_proto->data_type() == caffe2::TensorProto::FLOAT) {
(tensor->mutable_data<float>())[0] = tensor_proto->float_data(0);
}
// todo: for other types
}
}

void runNetwork(
shared_ptr<caffe2::Workspace> workspace,
caffe2::NetDef& net_def,
map<string, caffe2::TensorProtos>& tensor_protos_map,
const bool wipe_cache,
const bool run_individual,
const int warmup,
Expand All @@ -194,6 +227,7 @@ void runNetwork(
caffe2::ObserverConfig::initSampleRate(1, 1, 1, run_individual, warmup);
LOG(INFO) << "Running warmup runs.";
for (int i = 0; i < warmup; ++i) {
fillInputBlob(workspace, tensor_protos_map, i);
CAFFE_ENFORCE(net->Run(), "Warmup run ", i, " has failed.");
}

Expand All @@ -208,6 +242,7 @@ void runNetwork(
".");
for (int i = 0; i < iter; ++i) {
caffe2::ObserverConfig::initSampleRate(1, 1, 1, 0, warmup);
fillInputBlob(workspace, tensor_protos_map, i);
CAFFE_ENFORCE(net->Run(), "Main run ", i, " has failed.");
if (wipe_cache) {
caffe2::wipe_cache();
Expand Down
7 changes: 7 additions & 0 deletions binaries/benchmark_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "caffe2/core/operator.h"
#include "caffe2/utils/string_utils.h"

using std::map;
using std::shared_ptr;
using std::string;
using std::vector;
Expand Down Expand Up @@ -73,10 +74,15 @@ void setOperatorEngine(caffe2::NetDef*, const string&);
void loadInput(
shared_ptr<caffe2::Workspace>,
const bool,
map<string, caffe2::TensorProtos>&,
const string&,
const string&,
const string&,
const string&);
void fillInputBlob(
shared_ptr<caffe2::Workspace>,
map<string, caffe2::TensorProtos>&,
int iteration);
void writeOutput(
shared_ptr<caffe2::Workspace>,
const bool,
Expand All @@ -86,6 +92,7 @@ void writeOutput(
void runNetwork(
shared_ptr<caffe2::Workspace>,
caffe2::NetDef&,
map<string, caffe2::TensorProtos>&,
const bool,
const bool,
const int,
Expand Down
5 changes: 5 additions & 0 deletions binaries/caffe2_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "binaries/benchmark_helper.h"

using std::make_shared;
using std::map;
using std::string;
using std::vector;

Expand Down Expand Up @@ -96,9 +97,12 @@ int main(int argc, char** argv) {
setDeviceType(&net_def, run_dev);
setOperatorEngine(&net_def, caffe2::FLAGS_backend);

map<string, caffe2::TensorProtos> tensor_protos_map;

loadInput(
workspace,
run_on_gpu,
tensor_protos_map,
caffe2::FLAGS_input,
caffe2::FLAGS_input_file,
caffe2::FLAGS_input_dims,
Expand All @@ -107,6 +111,7 @@ int main(int argc, char** argv) {
runNetwork(
workspace,
net_def,
tensor_protos_map,
caffe2::FLAGS_wipe_cache,
caffe2::FLAGS_run_individual,
caffe2::FLAGS_warmup,
Expand Down
49 changes: 49 additions & 0 deletions binaries/tsv_2_proto.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2016-present, Facebook, Inc.
*
* 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 <sstream>
#include <string>

#include "caffe2/core/blob_serialization.h"
#include "caffe2/core/db.h"
#include "caffe2/core/init.h"
#include "caffe2/core/logging.h"
#include "caffe2/proto/caffe2.pb.h"
#include "caffe2/utils/proto_utils.h"

CAFFE2_DEFINE_string(f_in, "", "The input data file name.");
CAFFE2_DEFINE_string(f_out, "", "The output data file name.");

int main(int argc, char** argv) {
caffe2::GlobalInit(&argc, &argv);
std::ifstream f_in(caffe2::FLAGS_f_in);
std::ofstream f_out(caffe2::FLAGS_f_out);
std::string line;
caffe2::TensorProtos tensor_protos;
while (std::getline(f_in, line)) {
caffe2::TensorProto* data = tensor_protos.add_protos();
data->set_data_type(caffe2::TensorProto::STRING);
data->add_dims(0);
data->add_string_data(line);
data->set_name("text");
}
f_in.close();
std::string output_str;
tensor_protos.SerializeToString(&output_str);
f_out << output_str;
f_out.close();
return 0;
}
2 changes: 1 addition & 1 deletion caffe2/contrib/opencl/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ OpenCLContextSingleton::OpenCLContextSingleton() {
}
device = devices[device_id];

context = cl::Context({device});
context = cl::Context({device});
queue = cl::CommandQueue(context, device);
}

Expand Down
89 changes: 66 additions & 23 deletions caffe2/contrib/prof/profiling_annotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,97 @@
#pragma once

#include "caffe2/contrib/prof/prof_dag_net.h"
#include "caffe2/core/nomnigraph/include/nomnigraph/Representations/NeuralNet.h"

using nom::repr::Annotation;

namespace caffe2 {
namespace contrib {
namespace prof {

// Annotations used when profiling a NeuralNetOperator.
class ProfilingOperatorAnnotation : public Annotation {
// Accumulates data points and generates two point summary: mean, stddev.
class TwoNumberStats {
public:
ProfilingOperatorAnnotation()
: Annotation(AnnotationKind::ProfilingOperator) {}
// LLVM-style RTTI implementation.
static bool classof(const Annotation* annotation) {
return annotation->getKind() == AnnotationKind::ProfilingOperator;
TwoNumberStats() : sum_(0), squareSum_(0), count_(0) {}
// To prepopulate state of the TwoNumberStats accumulator.
TwoNumberStats(float mean, float stddev, int count)
: sum_(mean * count),
squareSum_((stddev * stddev + mean * mean) * count),
count_(count) {}
void addPoint(float point) {
sum_ += point;
squareSum_ += point * point;
count_++;
}
float getMean() const {
if (count_ == 0) {
return 0;
}
return sum_ / count_;
}
// Returns population stddev.
float getStddev() const {
if (count_ == 0) {
return 0;
}
return sqrt((count_ * squareSum_ - sum_ * sum_) / (count_ * count_));
}

private:
// Sum of data points.
float sum_;
// Sum of square of data points.
float squareSum_;
// Sample count.
int count_;
};

// Annotations used when profiling a NeuralNetOperator.
class ProfilingOperatorAnnotation {
public:
ProfilingOperatorAnnotation() {}
explicit ProfilingOperatorAnnotation(const ProfDAGProto& stats_proto)
: execution_time_ms_(
stats_proto.execution_time().mean(),
stats_proto.execution_time().stddev(),
stats_proto.execution_time().count()) {}
ProfilingOperatorAnnotation(ProfilingOperatorAnnotation&&) = default;
// Accessors
const Stats& execution_time_ms() const {
const TwoNumberStats& getExecutionTimeMs() const {
return execution_time_ms_;
}
Stats* mutable_execution_time_ms() {
TwoNumberStats* getMutableExecutionTimeMs() {
return &execution_time_ms_;
}

private:
// Statistics for how long this op took to execute.
Stats execution_time_ms_;
TwoNumberStats execution_time_ms_;
};

// Annotations used when profiling a NeuralNetData.
class ProfilingDataAnnotation : public Annotation {
// Annotations used when profiling a NeuralNetData. Data this class
// stores is translatable to/from BlobProfile. Note: translation
// may be lossy due to use of floating point arithmetic.
class ProfilingDataAnnotation {
public:
ProfilingDataAnnotation() : Annotation(AnnotationKind::ProfilingData) {}
// LLVM-style RTTI implementation.
static bool classof(const Annotation* annotation) {
return annotation->getKind() == AnnotationKind::ProfilingData;
}
ProfilingDataAnnotation() {}
explicit ProfilingDataAnnotation(const BlobProfile& profile)
: used_bytes_(
profile.bytes_used().mean(),
profile.bytes_used().stddev(),
profile.bytes_used().count()) {}
ProfilingDataAnnotation(ProfilingDataAnnotation&&) = default;
// Accessors
const Stats& used_bytes() const {
const TwoNumberStats& getUsedBytes() const {
return used_bytes_;
}
Stats* mutable_used_bytes() {
TwoNumberStats* getMutableUsedBytes() {
return &used_bytes_;
}

private:
// Statistics for how much data this tensor/parameter used (per invocation of
// the op that generated the data).
Stats used_bytes_;
TwoNumberStats used_bytes_;
};

} // namespace prof
} // namespace contrib
} // namespace caffe2
43 changes: 30 additions & 13 deletions caffe2/contrib/prof/profiling_annotations_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,41 @@
#include <gtest/gtest.h>

namespace caffe2 {
namespace contrib {
namespace prof {
namespace {

TEST(ProfilingAnnotationsTest, BasicAccess) {
TEST(TwoNumberStatsTest, ComputeAndGetOpStatsSummary) {
// e.g., 2 and 3
TwoNumberStats stats;
stats.addPoint(2);
stats.addPoint(3);
EXPECT_FLOAT_EQ(2.5, stats.getMean());
// Population standard deviation.
EXPECT_FLOAT_EQ(0.5, stats.getStddev());
}

TEST(TwoNumberStatsTest, TestRestore) {
// Expect that restore&recompute is still the same.
// E.g., 2 and 3 (above).
TwoNumberStats stats(2.5, 0.5, 2);
// Expect that restore&recompute is still the same.
EXPECT_FLOAT_EQ(2.5, stats.getMean());
// Population standard deviation.
EXPECT_FLOAT_EQ(0.5, stats.getStddev());
}

TEST(ProfilingAnnotationsTest, BasicAccessToActiveData) {
ProfilingOperatorAnnotation op_annotation;
op_annotation.mutable_execution_time_ms()->sum = 5;
op_annotation.getMutableExecutionTimeMs()->addPoint(5);
EXPECT_EQ(5, op_annotation.getExecutionTimeMs().getMean());

ProfilingDataAnnotation data_annotation;
data_annotation.mutable_used_bytes()->sum = 7;
auto* op_annotation_ptr =
dyn_cast<ProfilingOperatorAnnotation>(&op_annotation);
ASSERT_NE(nullptr, op_annotation_ptr);
EXPECT_EQ(5, op_annotation_ptr->execution_time_ms().sum);
auto* data_annotation_ptr =
dyn_cast<ProfilingDataAnnotation>(&data_annotation);
ASSERT_NE(nullptr, data_annotation_ptr);
EXPECT_EQ(7, data_annotation_ptr->used_bytes().sum);
EXPECT_EQ(nullptr, dyn_cast<ProfilingOperatorAnnotation>(&data_annotation));
EXPECT_EQ(nullptr, dyn_cast<ProfilingDataAnnotation>(&op_annotation));
data_annotation.getMutableUsedBytes()->addPoint(7);
EXPECT_EQ(7, data_annotation.getUsedBytes().getMean());
}

} // namespace
} // namespace prof
} // namespace contrib
} // namespace caffe2
Loading

0 comments on commit edb88b5

Please sign in to comment.