Use TryGetNodeAttr instead of GetNodeAttr in a few places

This reduces unnecessary non-OK Status constructions which in turn simplifies
debugging (logging or breakpointing in Status::Status becomes more meaningful).

PiperOrigin-RevId: 357611556
Change-Id: I816dec5e474611e60c53eafcd07666fa69f58d99
This commit is contained in:
Sanjoy Das 2021-02-15 14:22:05 -08:00 committed by TensorFlower Gardener
parent 5292800ba9
commit 2e3d1a21cb
2 changed files with 5 additions and 6 deletions

View File

@ -43,7 +43,7 @@ bool IsCpuGpuCompile(const Graph* graph) {
for (Node* n : graph->nodes()) { for (Node* n : graph->nodes()) {
string name; string name;
// Only consider nodes being compiled. // Only consider nodes being compiled.
if (!GetNodeAttr(n->attrs(), kXlaClusterIdAttr, &name).ok()) continue; if (!TryGetNodeAttr(n->attrs(), kXlaClusterIdAttr, &name)) continue;
// Early return for any node with a device that is not a CPU or GPU. // Early return for any node with a device that is not a CPU or GPU.
DeviceNameUtils::ParsedName parsed; DeviceNameUtils::ParsedName parsed;
if (DeviceNameUtils::ParseFullName(n->requested_device(), &parsed)) { if (DeviceNameUtils::ParseFullName(n->requested_device(), &parsed)) {
@ -58,8 +58,8 @@ bool IsCpuGpuCompile(const Graph* graph) {
// Checks if a graph node is marked to be a guaranteed constant. // Checks if a graph node is marked to be a guaranteed constant.
bool is_guaranteed_constant(const Node& n) { bool is_guaranteed_constant(const Node& n) {
bool guaranteed_constant = false; bool guaranteed_constant = false;
if (!GetNodeAttr(n.attrs(), "_is_guaranteed_constant", &guaranteed_constant) if (!TryGetNodeAttr(n.attrs(), "_is_guaranteed_constant",
.ok()) { &guaranteed_constant)) {
return false; return false;
} }
return guaranteed_constant; return guaranteed_constant;

View File

@ -397,9 +397,8 @@ XlaOpRegistry::CompileTimeConstantInputArgNames(const string& op) {
const std::unordered_set<string>* compile_time_constant_inputs; const std::unordered_set<string>* compile_time_constant_inputs;
if (GetNodeAttr(node_def, kXlaCompileTimeConstantInputsAttr, if (TryGetNodeAttr(node_def, kXlaCompileTimeConstantInputsAttr,
&compile_time_constant_inputs_vect_from_attr) &compile_time_constant_inputs_vect_from_attr)) {
.ok()) {
absl::c_copy(compile_time_constant_inputs_vect_from_attr, absl::c_copy(compile_time_constant_inputs_vect_from_attr,
std::inserter(compile_time_constant_inputs_from_attr, std::inserter(compile_time_constant_inputs_from_attr,
compile_time_constant_inputs_from_attr.end())); compile_time_constant_inputs_from_attr.end()));