Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit cbbdf34

Browse files
Merge branch 'master' into r0.12
2 parents 43baa15 + d46b530 commit cbbdf34

14 files changed

+335
-58
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ if (NOT USE_PRE_BUILT_NGRAPH)
239239
ExternalProject_Add(
240240
ext_ngraph
241241
GIT_REPOSITORY https://github.com/NervanaSystems/ngraph
242-
GIT_TAG v0.17.0-rc.1
242+
GIT_TAG v0.18.0-rc.1
243243
CMAKE_ARGS
244244
-DNGRAPH_DISTRIBUTED_ENABLE=${NGRAPH_DISTRIBUTED_ENABLE}
245245
-DNGRAPH_INSTALL_PREFIX=${NGRAPH_ARTIFACTS_DIR}

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ a variety of nGraph-enabled backends: CPU, GPU, and custom silicon like the
4747
This will produce something like this:
4848

4949
TensorFlow version: 1.13.1
50-
nGraph bridge version: b'0.12.0-rc4'
51-
nGraph version used for this build: b'0.17.0-rc.1+045b71e'
50+
nGraph bridge version: b'0.12.0-rc5'
51+
nGraph version used for this build: b'0.18.0-rc.1+55e1e17'
5252
TensorFlow version used for this build: v1.13.1-0-g6612da8951
5353
CXX11_ABI flag used for this build: 1
5454

bazel/WORKSPACE

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ tf_configure(
2525
http_archive(
2626
name = "ngraph",
2727
build_file = "//:bazel/ngraph.BUILD",
28-
sha256 = "517f2430ab1434021c2c4e3daf6f52cc855e4134632ed7c517a2c9c4b2c28f6b",
29-
strip_prefix = "ngraph-0.17.0-rc.1",
28+
sha256 = "8a0618901d96e016684fb9dc2b2e29fb648e5b32085bfbc6cc24b152bab5e8aa",
29+
strip_prefix = "ngraph-0.18.0-rc.1",
3030
urls = [
31-
"https://mirror.bazel.build/github.com/NervanaSystems/ngraph/archive/v0.17.0-rc.1.tar.gz",
32-
"https://github.com/NervanaSystems/ngraph/archive/v0.17.0-rc.1.tar.gz",
31+
"https://mirror.bazel.build/github.com/NervanaSystems/ngraph/archive/v0.18.0-rc.1.tar.gz",
32+
"https://github.com/NervanaSystems/ngraph/archive/v0.18.0-rc.1.tar.gz",
3333
],
3434
)
3535

build_ngtf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def main():
2424
'''
2525

2626
# Component versions
27-
ngraph_version = "v0.17.0-rc.1"
27+
ngraph_version = "v0.18.0-rc.1"
2828
tf_version = "v1.13.1"
2929

3030
# Command line parser options

python/CreatePipWhl.cmake

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ if (PYTHON)
4747
file(GLOB NGRAPH_LIB_FILES "${NGTF_INSTALL_DIR}/${LIB_SUFFIX}/lib*")
4848

4949
# Copy the ngraph_bridge include from install
50+
message(STATUS "NGTF_INSTALL_DIR: ${NGTF_INSTALL_DIR}")
51+
5052
file(
51-
COPY "${NGTF_INSTALL_DIR}/include"
53+
COPY "${NGRAPH_INSTALL_DIR}/include"
5254
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/python/ngraph_bridge"
5355
)
5456

python/setup.in.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_tag(self):
3939

4040
setup(
4141
name='ngraph_tensorflow_bridge',
42-
version='0.12.0rc4',
42+
version='0.12.0rc5',
4343
description='Intel nGraph compiler and runtime for TensorFlow',
4444
long_description=long_description,
4545
long_description_content_type="text/markdown",
@@ -52,7 +52,7 @@ def get_tag(self):
5252
package_data=
5353
{
5454
'ngraph_bridge': [
55-
"include/ngraph/*",
55+
"include/ngraph/**/*",
5656
@ngraph_libraries@ @license_files@ @licence_top_level@
5757
],
5858
},

src/ngraph_builder.cc

+87
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
#include "ngraph_builder.h"
1818
#include "ngraph/op/util/logical_reduction.hpp"
19+
#include "ngraph_backend_manager.h"
1920
#include "ngraph_conversions.h"
2021
#include "ngraph_log.h"
22+
#include "ngraph_mark_for_clustering.h"
2123
#include "ngraph_utils.h"
2224

2325
#include "ngraph/builder/autobroadcast.hpp"
@@ -1914,6 +1916,90 @@ static Status TranslateFusedBatchNormGradOp(
19141916
return Status::OK();
19151917
}
19161918

1919+
static Status TranslateGatherV2Op(
1920+
const Node* op, const std::vector<const Tensor*>& static_input_map,
1921+
Builder::OpMap& ng_op_map) {
1922+
shared_ptr<ng::Node> ng_input;
1923+
TF_RETURN_IF_ERROR(GetInputNode(ng_op_map, op, 0, &ng_input));
1924+
1925+
std::vector<int64> tf_indices;
1926+
TF_RETURN_IF_ERROR(
1927+
GetStaticInputVector(op, 1, static_input_map, &tf_indices));
1928+
// It seems indices cannot be negative, so no need to handle that
1929+
std::vector<size_t> indices(tf_indices.size());
1930+
std::transform(tf_indices.begin(), tf_indices.end(), indices.begin(),
1931+
[](int64 x) { return (size_t)(x); });
1932+
1933+
std::vector<int64> tf_axis;
1934+
TF_RETURN_IF_ERROR(GetStaticInputVector(op, 2, static_input_map, &tf_axis));
1935+
1936+
if (tf_axis.size() > 1) {
1937+
return errors::Internal("Found axis in GatherV2 op (", op->name(),
1938+
") translation to be non scalar, of size ",
1939+
tf_axis.size());
1940+
}
1941+
1942+
std::string backend_name;
1943+
TF_RETURN_IF_ERROR(ngraph_bridge::GetNodeBackend(op, &backend_name));
1944+
1945+
if (backend_name != "NNPI") {
1946+
return errors::Internal("In translating GatherV2 op ", op->name(),
1947+
" found requested backend ", backend_name,
1948+
" which is unsupported");
1949+
}
1950+
1951+
ng::runtime::Backend* backend = BackendManager::GetBackend(backend_name);
1952+
auto coords = ng::Coordinate(indices);
1953+
// Negative axis is supported. Accounting for that
1954+
auto ng_input_shape = ng_input->get_shape();
1955+
size_t ng_input_rank = ng_input_shape.size();
1956+
size_t axis;
1957+
if (tf_axis[0] >= 0) {
1958+
axis = tf_axis[0];
1959+
} else {
1960+
axis = tf_axis[0] + ng_input_rank;
1961+
}
1962+
if (axis < 0 || axis >= ng_input_rank) {
1963+
return errors::InvalidArgument("Expected axis in the range [-",
1964+
ng_input_rank, ", ", ng_input_rank,
1965+
"), but got ", tf_axis[0]);
1966+
}
1967+
1968+
for (size_t indices_idx = 0; indices_idx < indices.size(); indices_idx++) {
1969+
if (indices[indices_idx] >= ng_input_shape[axis]) {
1970+
// TODO: this error returnign must be generalized when indices = vector of
1971+
// vectors is supported
1972+
return errors::InvalidArgument("indices[0,", indices_idx, "] = ",
1973+
indices[indices_idx], " is not in [0, ",
1974+
ng_input_shape[axis], ")");
1975+
}
1976+
}
1977+
1978+
vector<size_t> possibly_empty_node_size(ng_input_shape);
1979+
possibly_empty_node_size[axis] = indices.size();
1980+
1981+
if (std::any_of(possibly_empty_node_size.begin(),
1982+
possibly_empty_node_size.end(),
1983+
[](size_t x) { return x == 0; })) {
1984+
std::vector<std::string> const_values(
1985+
ng::shape_size(possibly_empty_node_size), "0");
1986+
auto ng_empty = ConstructNgNode<ng::op::Constant>(
1987+
op->name(), ng_input->get_element_type(),
1988+
ng::Shape(possibly_empty_node_size), const_values);
1989+
SaveNgOp(ng_op_map, op->name(), ng_empty);
1990+
} else {
1991+
shared_ptr<ng::Node> ng_gather =
1992+
backend->get_backend_op("Gather", &ng_input, &coords, &axis);
1993+
if (ng_gather == nullptr) {
1994+
return errors::Internal("In translating GatherV2 op ", op->name(),
1995+
" backend could not return valid ngraph node");
1996+
}
1997+
SaveNgOp(ng_op_map, op->name(), ng_gather);
1998+
}
1999+
2000+
return Status::OK();
2001+
}
2002+
19172003
static Status TranslateFusedConv2DOp(
19182004
const Node* op, const std::vector<const Tensor*>& static_input_map,
19192005
Builder::OpMap& ng_op_map) {
@@ -4252,6 +4338,7 @@ const static std::map<
42524338
{"FusedBatchNorm", TranslateFusedBatchNormOp},
42534339
{"FusedBatchNormV2", TranslateFusedBatchNormOp},
42544340
{"FusedBatchNormGrad", TranslateFusedBatchNormGradOp},
4341+
{"GatherV2", TranslateGatherV2Op},
42554342
{"_FusedConv2D", TranslateFusedConv2DOp},
42564343
{"Greater", TranslateBinaryOp<ngraph::op::Greater>},
42574344
{"GreaterEqual", TranslateBinaryOp<ngraph::op::GreaterEq>},

src/ngraph_mark_for_clustering.cc

+32-18
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ Status MarkForClustering(Graph* graph,
430430
// DT_FLOAT
431431
type_constraint_map["FusedBatchNormV2"]["T"] = {DT_FLOAT};
432432
type_constraint_map["FusedBatchNormGrad"]["T"] = NGraphNumericDTypes();
433+
type_constraint_map["GatherV2"]["Tparams"] = NGraphDTypes();
434+
type_constraint_map["GatherV2"]["Tindices"] = NGraphIndexDTypes();
435+
type_constraint_map["GatherV2"]["Taxis"] = NGraphIndexDTypes();
433436
type_constraint_map["_FusedConv2D"]["T"] = NGraphRealDTypes();
434437
type_constraint_map["Greater"]["T"] = NGraphDTypes();
435438
type_constraint_map["GreaterEqual"]["T"] = NGraphDTypes();
@@ -567,6 +570,7 @@ Status MarkForClustering(Graph* graph,
567570
set_attributes_map["Conv2DBackpropInput"] = SetStaticInputs({0});
568571
set_attributes_map["ExpandDims"] = SetStaticInputs({1});
569572
set_attributes_map["Fill"] = SetStaticInputs({0});
573+
set_attributes_map["GatherV2"] = SetStaticInputs({1, 2});
570574
set_attributes_map["Max"] = SetStaticInputs({1});
571575
set_attributes_map["Mean"] = SetStaticInputs({1});
572576
set_attributes_map["Min"] = SetStaticInputs({1});
@@ -608,6 +612,33 @@ Status MarkForClustering(Graph* graph,
608612
}
609613
}
610614

615+
// Set Attributes for nodes marked for clustering
616+
// 1. Set Attribute "_ngraph_marked_for_clustering" as "true"
617+
// 2. Set the backend for each op
618+
// 3. Set any other attributes as defined in set_attribute_map
619+
string current_backend = BackendManager::GetCurrentlySetBackendName();
620+
const char* ng_backend_env_value = std::getenv("NGRAPH_TF_BACKEND");
621+
if (ng_backend_env_value != nullptr) {
622+
string backend_env = std::string(ng_backend_env_value);
623+
if (backend_env.empty() ||
624+
!BackendManager::IsSupportedBackend(backend_env)) {
625+
return errors::Internal("NGRAPH_TF_BACKEND: ", backend_env,
626+
" is not supported");
627+
}
628+
current_backend = backend_env;
629+
// TODO: set backend. Then don't use current_backend
630+
}
631+
632+
// Right now it cannot be inside the if(!initialized) block, because it is
633+
// backend dependent, which might change with different sess.run()s
634+
confirmation_function_map["GatherV2"] = [&current_backend](Node* n,
635+
bool* result) {
636+
// TODO: replace current_backend ->
637+
// BackendManager::GetCurrentlySetBackendName()
638+
*result = (current_backend == "NNPI");
639+
return Status::OK();
640+
};
641+
611642
std::unordered_map<string, int> no_support_histogram;
612643
std::unordered_map<string, int> fail_confirmation_histogram;
613644
std::unordered_map<string, int> fail_constraint_histogram;
@@ -692,23 +723,6 @@ Status MarkForClustering(Graph* graph,
692723
std::cout << "\n";
693724
}
694725

695-
// Set Attributes for nodes marked for clustering
696-
// 1. Set Attribute "_ngraph_marked_for_clustering" as "true"
697-
// 2. Set the backend for each op
698-
// 3. Set any other attributes as defined in set_attribute_map
699-
string current_backend = BackendManager::GetCurrentlySetBackendName();
700-
const char* ng_backend_env_value = std::getenv("NGRAPH_TF_BACKEND");
701-
if (ng_backend_env_value != nullptr) {
702-
string backend_env = std::string(ng_backend_env_value);
703-
if (backend_env.empty() ||
704-
!BackendManager::IsSupportedBackend(backend_env)) {
705-
return errors::Internal("NGRAPH_TF_BACKEND: ", backend_env,
706-
" is not supported");
707-
}
708-
current_backend = backend_env;
709-
}
710-
NGRAPH_VLOG(5) << "Found NG Backend " << current_backend;
711-
712726
for (auto node : nodes_marked_for_clustering) {
713727
// TODO(amprocte): move attr name to a constant
714728
node->AddAttr("_ngraph_marked_for_clustering", true);
@@ -743,7 +757,7 @@ bool InputIsStatic(const Node* node, int index) {
743757
return std::find(inputs.begin(), inputs.end(), index) != inputs.end();
744758
}
745759

746-
Status GetNodeBackend(Node* node, string* backend_name) {
760+
Status GetNodeBackend(const Node* node, string* backend_name) {
747761
// TODO(amprocte): move attr name to a constant
748762
NGRAPH_VLOG(5) << "Getting backend " << node->name();
749763
TF_RETURN_IF_ERROR(

src/ngraph_mark_for_clustering.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Status MarkForClustering(Graph* graph, std::vector<string> skip_these_nodes);
2828
bool NodeIsMarkedForClustering(const Node* node);
2929
void GetStaticInputs(const Node* node, std::vector<int32>* inputs);
3030
bool InputIsStatic(const Node* node, int index);
31-
Status GetNodeBackend(Node* node, string* backend_name);
31+
Status GetNodeBackend(const Node* node, string* backend_name);
3232
void SetNodeBackend(Node* node, string& backend_name);
3333
} // namespace ngraph_bridge
3434

src/version.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// candidate such as v0.7.0-rc0
3131
// The code in master will always have the last released version number
3232
// with a suffix of '-master'
33-
#define NG_TF_VERSION_SUFFIX "-rc4"
33+
#define NG_TF_VERSION_SUFFIX "-rc5"
3434

3535
#define VERSION_STR_HELPER(x) #x
3636
#define VERSION_STR(x) VERSION_STR_HELPER(x)

test/python/tensorflow/python_tests_list.txt

+20-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,26 @@ depthtospace_op_test.DepthToSpaceTest.testDepthInterleavedLarger
171171
depthtospace_op_test.DepthToSpaceTest.testNonSquare
172172

173173
#dequantize_op_test.DequantizeOpTest.testBasicQuint8
174-
#dequantize_op_test.DequantizeOpTest.testBasicQint8
174+
#dequantize_op_test.DequantizeOpTest.testBasicQint8
175+
176+
177+
# Note that all these test will pass on CPU (except testUInt32AndUInt64), because on CPU gather falls back to TF
178+
# In case of NNPI all except the last pass. But CI wont be tracking it because CI runs on CPU backend only
179+
gather_op_test.GatherTest.testBadAxis
180+
gather_op_test.GatherTest.testBadIndicesCPU
181+
#gather_op_test.GatherTest.testEmptySlices ...failure in backend due to int64
182+
#gather_op_test.GatherTest.testScalar1D ...failure in backend due to int64
183+
#gather_op_test.GatherTest.testScalar2D ...failure in backend due to int64
184+
#gather_op_test.GatherTest.testSimpleTwoD32 ...failure in backend due to int64
185+
gather_op_test.GatherTest.testString
186+
#gather_op_test.GatherTest.testUInt32AndUInt64 ...Unsupported TensorFlow data type: DT_UINT32
187+
gather_op_test.GatherTest.testUnknownAxis
188+
gather_op_test.GatherTest.testUnknownIndices
189+
gather_op_test.GatherTest.test_session
190+
#gather_op_test.GatherTest.testHigherRank ..ERROR
191+
192+
# This test set fails on NNPI
193+
#batch_gather_op_test
175194

176195
identity_n_op_py_test.IdentityNOpTest.testInt32String_6
177196
identity_n_op_py_test.IdentityNOpTest.testInt32_shapes

0 commit comments

Comments
 (0)