Improve EagerContext::SelectDevice performance.
Improve EagerContext::SelectDevice performance.

Benchmarks show that the performance of the function more than
doubles, and that now most of it is taken by string and device type
equality comparisons.

The functions that EagerContext::SelectDevice calls in order to do its
job are a lot more generic than they need to be, as they build _lists_
of available devices, when all SelectDevice needs is to select the "best"
available device that is also supported. This boils down to a simple
double-loop as defined in this change.

This double-loop avoids memory allocation, and its O(n^2) complexity
is not a problem because "n" is small (number of available devices).

There is no behavior change, so the existing test does not need to be
modified.

PiperOrigin-RevId: 293260590
Change-Id: I3e2ea5c5fb66a9627baf7b32afc08ac08444a3f1

petewarden/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,gautam1858/tensorflow,tensorflow/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,Intel-Corporation/tensorflow,Intel-Corporation/tensorflow,gautam1858/tensorflow,aldian/tensorflow,xzturn/tensorflow,xzturn/tensorflow,gunan/tensorflow,tensorflow/tensorflow,gautam1858/tensorflow,aam-at/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,tensorflow/tensorflow-pywrap_saved_model,tensorflow/tensorflow-pywrap_tf_optimizer,davidzchen/tensorflow,annarev/tensorflow,gunan/tensorflow,gautam1858/tensorflow,renyi533/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,cxxgtxy/tensorflow,karllessard/tensorflow,freedomtan/tensorflow,karllessard/tensorflow,xzturn/tensorflow,tensorflow/tensorflow,renyi533/tensorflow,petewarden/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,renyi533/tensorflow,gautam1858/tensorflow,petewarden/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,freedomtan/tensorflow,tensorflow/tensorflow,annarev/tensorflow,frreiss/tensorflow-fred,paolodedios/tensorflow,frreiss/tensorflow-fred,gunan/tensorflow,tensorflow/tensorflow,davidzchen/tensorflow,renyi533/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,renyi533/tensorflow,freedomtan/tensorflow,gunan/tensorflow,aam-at/tensorflow,paolodedios/tensorflow,annarev/tensorflow,paolodedios/tensorflow,tensorflow/tensorflow,gautam1858/tensorflow,karllessard/tensorflow,aldian/tensorflow,karllessard/tensorflow,Intel-tensorflow/tensorflow,Intel-tensorflow/tensorflow,annarev/tensorflow,renyi533/tensorflow,aam-at/tensorflow,cxxgtxy/tensorflow,xzturn/tensorflow,gautam1858/tensorflow,Intel-tensorflow/tensorflow,davidzchen/tensorflow,davidzchen/tensorflow,tensorflow/tensorflow,frreiss/tensorflow-fred,tensorflow/tensorflow-pywrap_saved_model,Intel-tensorflow/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,gunan/tensorflow,yongtang/tensorflow,Intel-Corporation/tensorflow,frreiss/tensorflow-fred,xzturn/tensorflow,aam-at/tensorflow,aam-at/tensorflow,paolodedios/tensorflow,xzturn/tensorflow,Intel-tensorflow/tensorflow,davidzchen/tensorflow,karllessard/tensorflow,yongtang/tensorflow,aam-at/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,tensorflow/tensorflow-experimental_link_static_libraries_once,aam-at/tensorflow,cxxgtxy/tensorflow,petewarden/tensorflow,renyi533/tensorflow,davidzchen/tensorflow,cxxgtxy/tensorflow,aldian/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,tensorflow/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,petewarden/tensorflow,yongtang/tensorflow,jhseu/tensorflow,aam-at/tensorflow,xzturn/tensorflow,sarvex/tensorflow,jhseu/tensorflow,tensorflow/tensorflow-pywrap_saved_model,davidzchen/tensorflow,frreiss/tensorflow-fred,sarvex/tensorflow,renyi533/tensorflow,sarvex/tensorflow,gautam1858/tensorflow,davidzchen/tensorflow,davidzchen/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,tensorflow/tensorflow,Intel-tensorflow/tensorflow,aam-at/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,tensorflow/tensorflow-pywrap_saved_model,jhseu/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,renyi533/tensorflow,aldian/tensorflow,jhseu/tensorflow,jhseu/tensorflow,Intel-tensorflow/tensorflow,petewarden/tensorflow,xzturn/tensorflow,paolodedios/tensorflow,annarev/tensorflow,paolodedios/tensorflow,annarev/tensorflow,gunan/tensorflow,frreiss/tensorflow-fred,freedomtan/tensorflow,freedomtan/tensorflow,aldian/tensorflow,aam-at/tensorflow,yongtang/tensorflow,Intel-Corporation/tensorflow,Intel-Corporation/tensorflow,frreiss/tensorflow-fred,gautam1858/tensorflow,annarev/tensorflow,cxxgtxy/tensorflow,gunan/tensorflow,Intel-tensorflow/tensorflow,jhseu/tensorflow,annarev/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,aam-at/tensorflow,sarvex/tensorflow,gunan/tensorflow,Intel-Corporation/tensorflow,petewarden/tensorflow,freedomtan/tensorflow,jhseu/tensorflow,petewarden/tensorflow,jhseu/tensorflow,gunan/tensorflow,xzturn/tensorflow,tensorflow/tensorflow-pywrap_saved_model,yongtang/tensorflow,freedomtan/tensorflow,sarvex/tensorflow,davidzchen/tensorflow,petewarden/tensorflow,gunan/tensorflow,davidzchen/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,tensorflow/tensorflow-pywrap_saved_model,karllessard/tensorflow,freedomtan/tensorflow,yongtang/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,Intel-tensorflow/tensorflow,xzturn/tensorflow,tensorflow/tensorflow-pywrap_saved_model,paolodedios/tensorflow,karllessard/tensorflow,Intel-tensorflow/tensorflow,yongtang/tensorflow,Intel-tensorflow/tensorflow,jhseu/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,freedomtan/tensorflow,aldian/tensorflow,renyi533/tensorflow,yongtang/tensorflow,frreiss/tensorflow-fred,Intel-Corporation/tensorflow,frreiss/tensorflow-fred,gunan/tensorflow,tensorflow/tensorflow-pywrap_saved_model,paolodedios/tensorflow,jhseu/tensorflow,aldian/tensorflow,annarev/tensorflow,xzturn/tensorflow,frreiss/tensorflow-fred,gautam1858/tensorflow,karllessard/tensorflow,Intel-Corporation/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,petewarden/tensorflow,frreiss/tensorflow-fred,renyi533/tensorflow,karllessard/tensorflow,yongtang/tensorflow,cxxgtxy/tensorflow,freedomtan/tensorflow,yongtang/tensorflow,frreiss/tensorflow-fred,paolodedios/tensorflow,paolodedios/tensorflow,gautam1858/tensorflow,karllessard/tensorflow,tensorflow/tensorflow-pywrap_saved_model,tensorflow/tensorflow-pywrap_saved_model,petewarden/tensorflow,tensorflow/tensorflow,cxxgtxy/tensorflow,aldian/tensorflow,gautam1858/tensorflow,tensorflow/tensorflow,sarvex/tensorflow,annarev/tensorflow,davidzchen/tensorflow,freedomtan/tensorflow,aam-at/tensorflow,paolodedios/tensorflow,jhseu/tensorflow,annarev/tensorflow,jhseu/tensorflow,karllessard/tensorflow,cxxgtxy/tensorflow,renyi533/tensorflow,gunan/tensorflow,sarvex/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,sarvex/tensorflow,freedomtan/tensorflow,petewarden/tensorflow,xzturn/tensorflow,yongtang/tensorflow,tensorflow/tensorflow-pywrap_saved_model