Reduce overhead of constructing an `OpKernelContext` on non-GPU devices.
Reduce overhead of constructing an `OpKernelContext` on non-GPU devices.

The current `OpKernelContext` constructor unconditionally makes a virtual call to get an allocator that is only used when the kernel is running on a GPU device. Since we can tell if this is necessary after the call to `params_->ensure_eigen_gpu_device()`, we can avoid the call, plus the virtual call to `ReinitializeGpuDevice()`, when we know that it is not a GPU device.

PiperOrigin-RevId: 203523500

hehongliang/tensorflow,asimshankar/tensorflow,alsrgv/tensorflow,dancingdan/tensorflow,ppwwyyxx/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,seanli9jan/tensorflow,jbedorf/tensorflow,AnishShah/tensorflow,brchiu/tensorflow,jart/tensorflow,annarev/tensorflow,hehongliang/tensorflow,Intel-tensorflow/tensorflow,Intel-Corporation/tensorflow,freedomtan/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,sarvex/tensorflow,annarev/tensorflow,kobejean/tensorflow,petewarden/tensorflow,ppwwyyxx/tensorflow,jart/tensorflow,aselle/tensorflow,karllessard/tensorflow,girving/tensorflow,jbedorf/tensorflow,jalexvig/tensorflow,xodus7/tensorflow,xzturn/tensorflow,annarev/tensorflow,jendap/tensorflow,brchiu/tensorflow,ghchinoy/tensorflow,tensorflow/tensorflow,hehongliang/tensorflow,tensorflow/tensorflow-pywrap_saved_model,theflofly/tensorflow,annarev/tensorflow,Bismarrck/tensorflow,jendap/tensorflow,gunan/tensorflow,adit-chandra/tensorflow,jart/tensorflow,ghchinoy/tensorflow,yongtang/tensorflow,DavidNorman/tensorflow,manipopopo/tensorflow,girving/tensorflow,xzturn/tensorflow,ageron/tensorflow,jendap/tensorflow,aam-at/tensorflow,alsrgv/tensorflow,kevin-coder/tensorflow-fork,jhseu/tensorflow,alsrgv/tensorflow,chemelnucfin/tensorflow,davidzchen/tensorflow,ppwwyyxx/tensorflow,jalexvig/tensorflow,snnn/tensorflow,DavidNorman/tensorflow,hehongliang/tensorflow,aldian/tensorflow,kobejean/tensorflow,seanli9jan/tensorflow,dancingdan/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,davidzchen/tensorflow,adit-chandra/tensorflow,ghchinoy/tensorflow,ppwwyyxx/tensorflow,jendap/tensorflow,seanli9jan/tensorflow,DavidNorman/tensorflow,apark263/tensorflow,paolodedios/tensorflow,brchiu/tensorflow,cxxgtxy/tensorflow,jalexvig/tensorflow,dongjoon-hyun/tensorflow,frreiss/tensorflow-fred,caisq/tensorflow,dongjoon-hyun/tensorflow,chemelnucfin/tensorflow,Intel-tensorflow/tensorflow,AnishShah/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,yongtang/tensorflow,davidzchen/tensorflow,DavidNorman/tensorflow,aam-at/tensorflow,alsrgv/tensorflow,chemelnucfin/tensorflow,adit-chandra/tensorflow,alsrgv/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,AnishShah/tensorflow,aselle/tensorflow,aam-at/tensorflow,tensorflow/tensorflow-pywrap_saved_model,ppwwyyxx/tensorflow,apark263/tensorflow,Intel-Corporation/tensorflow,arborh/tensorflow,dongjoon-hyun/tensorflow,alshedivat/tensorflow,freedomtan/tensorflow,alsrgv/tensorflow,freedomtan/tensorflow,snnn/tensorflow,frreiss/tensorflow-fred,davidzchen/tensorflow,renyi533/tensorflow,DavidNorman/tensorflow,alsrgv/tensorflow,brchiu/tensorflow,ZhangXinNan/tensorflow,kevin-coder/tensorflow-fork,xzturn/tensorflow,Intel-Corporation/tensorflow,yongtang/tensorflow,snnn/tensorflow,annarev/tensorflow,freedomtan/tensorflow,hfp/tensorflow-xsmm,kobejean/tensorflow,theflofly/tensorflow,theflofly/tensorflow,jalexvig/tensorflow,xzturn/tensorflow,tensorflow/tensorflow,petewarden/tensorflow,dongjoon-hyun/tensorflow,aselle/tensorflow,chemelnucfin/tensorflow,dongjoon-hyun/tensorflow,sarvex/tensorflow,adit-chandra/tensorflow,davidzchen/tensorflow,gunan/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,paolodedios/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,aam-at/tensorflow,asimshankar/tensorflow,snnn/tensorflow,theflofly/tensorflow,arborh/tensorflow,gautam1858/tensorflow,arborh/tensorflow,AnishShah/tensorflow,aam-at/tensorflow,Intel-tensorflow/tensorflow,asimshankar/tensorflow,paolodedios/tensorflow,xzturn/tensorflow,renyi533/tensorflow,snnn/tensorflow,gautam1858/tensorflow,jendap/tensorflow,apark263/tensorflow,hfp/tensorflow-xsmm,chemelnucfin/tensorflow,renyi533/tensorflow,jbedorf/tensorflow,frreiss/tensorflow-fred,jbedorf/tensorflow,frreiss/tensorflow-fred,tensorflow/tensorflow-experimental_link_static_libraries_once,apark263/tensorflow,gautam1858/tensorflow,dongjoon-hyun/tensorflow,dancingdan/tensorflow,manipopopo/tensorflow,gunan/tensorflow,ZhangXinNan/tensorflow,jart/tensorflow,ZhangXinNan/tensorflow,manipopopo/tensorflow,tensorflow/tensorflow,ZhangXinNan/tensorflow,DavidNorman/tensorflow,asimshankar/tensorflow,renyi533/tensorflow,aam-at/tensorflow,AnishShah/tensorflow,adit-chandra/tensorflow,brchiu/tensorflow,tensorflow/tensorflow-pywrap_saved_model,tensorflow/tensorflow-pywrap_saved_model,jalexvig/tensorflow,ageron/tensorflow,cxxgtxy/tensorflow,petewarden/tensorflow,yongtang/tensorflow,tensorflow/tensorflow,arborh/tensorflow,tensorflow/tensorflow,manipopopo/tensorflow,Bismarrck/tensorflow,arborh/tensorflow,ppwwyyxx/tensorflow,sarvex/tensorflow,renyi533/tensorflow,snnn/tensorflow,Intel-tensorflow/tensorflow,xodus7/tensorflow,ageron/tensorflow,cxxgtxy/tensorflow,karllessard/tensorflow,brchiu/tensorflow,hfp/tensorflow-xsmm,yongtang/tensorflow,aselle/tensorflow,annarev/tensorflow,xodus7/tensorflow,hehongliang/tensorflow,apark263/tensorflow,gunan/tensorflow,petewarden/tensorflow,tensorflow/tensorflow-pywrap_saved_model,jendap/tensorflow,adit-chandra/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,renyi533/tensorflow,davidzchen/tensorflow,renyi533/tensorflow,ageron/tensorflow,paolodedios/tensorflow,alshedivat/tensorflow,aldian/tensorflow,tensorflow/tensorflow-pywrap_saved_model,jbedorf/tensorflow,dongjoon-hyun/tensorflow,alshedivat/tensorflow,jendap/tensorflow,karllessard/tensorflow,theflofly/tensorflow,petewarden/tensorflow,davidzchen/tensorflow,jart/tensorflow,xodus7/tensorflow,manipopopo/tensorflow,alsrgv/tensorflow,renyi533/tensorflow,ageron/tensorflow,girving/tensorflow,tensorflow/tensorflow-pywrap_saved_model,cxxgtxy/tensorflow,jhseu/tensorflow,ageron/tensorflow,chemelnucfin/tensorflow,yongtang/tensorflow,kobejean/tensorflow,alshedivat/tensorflow,dongjoon-hyun/tensorflow,manipopopo/tensorflow,theflofly/tensorflow,adit-chandra/tensorflow,jbedorf/tensorflow,sarvex/tensorflow,kobejean/tensorflow,chemelnucfin/tensorflow,jbedorf/tensorflow,ghchinoy/tensorflow,davidzchen/tensorflow,manipopopo/tensorflow,gautam1858/tensorflow,dancingdan/tensorflow,aam-at/tensorflow,kevin-coder/tensorflow-fork,aselle/tensorflow,annarev/tensorflow,tensorflow/tensorflow,annarev/tensorflow,asimshankar/tensorflow,jalexvig/tensorflow,apark263/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,jendap/tensorflow,gunan/tensorflow,frreiss/tensorflow-fred,jhseu/tensorflow,jhseu/tensorflow,jart/tensorflow,caisq/tensorflow,petewarden/tensorflow,yongtang/tensorflow,Bismarrck/tensorflow,tensorflow/tensorflow,frreiss/tensorflow-fred,alsrgv/tensorflow,aldian/tensorflow,arborh/tensorflow,xodus7/tensorflow,AnishShah/tensorflow,hfp/tensorflow-xsmm,asimshankar/tensorflow,xzturn/tensorflow,petewarden/tensorflow,brchiu/tensorflow,ghchinoy/tensorflow,kevin-coder/tensorflow-fork,Bismarrck/tensorflow,jart/tensorflow,snnn/tensorflow,ppwwyyxx/tensorflow,freedomtan/tensorflow,cxxgtxy/tensorflow,jbedorf/tensorflow,ZhangXinNan/tensorflow,gautam1858/tensorflow,arborh/tensorflow,chemelnucfin/tensorflow,alshedivat/tensorflow,tensorflow/tensorflow-pywrap_saved_model,tensorflow/tensorflow-experimental_link_static_libraries_once,ppwwyyxx/tensorflow,apark263/tensorflow,ZhangXinNan/tensorflow,tensorflow/tensorflow,gunan/tensorflow,aam-at/tensorflow,paolodedios/tensorflow,davidzchen/tensorflow,kevin-coder/tensorflow-fork,caisq/tensorflow,xzturn/tensorflow,xzturn/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,jart/tensorflow,tensorflow/tensorflow,arborh/tensorflow,girving/tensorflow,girving/tensorflow,tensorflow/tensorflow-pywrap_saved_model,brchiu/tensorflow,chemelnucfin/tensorflow,hfp/tensorflow-xsmm,girving/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,caisq/tensorflow,girving/tensorflow,jhseu/tensorflow,paolodedios/tensorflow,jart/tensorflow,aam-at/tensorflow,hfp/tensorflow-xsmm,adit-chandra/tensorflow,girving/tensorflow,Intel-tensorflow/tensorflow,ZhangXinNan/tensorflow,frreiss/tensorflow-fred,gautam1858/tensorflow,apark263/tensorflow,karllessard/tensorflow,jbedorf/tensorflow,petewarden/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,caisq/tensorflow,paolodedios/tensorflow,ghchinoy/tensorflow,snnn/tensorflow,xodus7/tensorflow,dancingdan/tensorflow,arborh/tensorflow,jalexvig/tensorflow,theflofly/tensorflow,hfp/tensorflow-xsmm,asimshankar/tensorflow,Bismarrck/tensorflow,gautam1858/tensorflow,karllessard/tensorflow,aldian/tensorflow,ZhangXinNan/tensorflow,freedomtan/tensorflow,apark263/tensorflow,paolodedios/tensorflow,aam-at/tensorflow,Bismarrck/tensorflow,hfp/tensorflow-xsmm,Intel-Corporation/tensorflow,kevin-coder/tensorflow-fork,hfp/tensorflow-xsmm,petewarden/tensorflow,snnn/tensorflow,ageron/tensorflow,ZhangXinNan/tensorflow,yongtang/tensorflow,gunan/tensorflow,theflofly/tensorflow,jhseu/tensorflow,tensorflow/tensorflow-pywrap_saved_model,manipopopo/tensorflow,kobejean/tensorflow,arborh/tensorflow,kobejean/tensorflow,Bismarrck/tensorflow,hehongliang/tensorflow,DavidNorman/tensorflow,asimshankar/tensorflow,ghchinoy/tensorflow,dancingdan/tensorflow,DavidNorman/tensorflow,kevin-coder/tensorflow-fork,Bismarrck/tensorflow,frreiss/tensorflow-fred,karllessard/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,ghchinoy/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,jhseu/tensorflow,jalexvig/tensorflow,adit-chandra/tensorflow,aldian/tensorflow,renyi533/tensorflow,jhseu/tensorflow,karllessard/tensorflow,asimshankar/tensorflow,asimshankar/tensorflow,jhseu/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,ageron/tensorflow,chemelnucfin/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,karllessard/tensorflow,brchiu/tensorflow,alshedivat/tensorflow,freedomtan/tensorflow,snnn/tensorflow,AnishShah/tensorflow,kobejean/tensorflow,manipopopo/tensorflow,adit-chandra/tensorflow,xzturn/tensorflow,aselle/tensorflow,renyi533/tensorflow,jalexvig/tensorflow,Bismarrck/tensorflow,Intel-tensorflow/tensorflow,petewarden/tensorflow,adit-chandra/tensorflow,DavidNorman/tensorflow,gautam1858/tensorflow,xodus7/tensorflow,girving/tensorflow,ghchinoy/tensorflow,jhseu/tensorflow,hehongliang/tensorflow,karllessard/tensorflow,Intel-tensorflow/tensorflow,jbedorf/tensorflow,arborh/tensorflow,adit-chandra/tensorflow,DavidNorman/tensorflow,Intel-Corporation/tensorflow,AnishShah/tensorflow,karllessard/tensorflow,kevin-coder/tensorflow-fork,dancingdan/tensorflow,DavidNorman/tensorflow,ppwwyyxx/tensorflow,jalexvig/tensorflow,seanli9jan/tensorflow,jart/tensorflow,caisq/tensorflow,Intel-tensorflow/tensorflow,Intel-Corporation/tensorflow,petewarden/tensorflow,chemelnucfin/tensorflow,ppwwyyxx/tensorflow,alshedivat/tensorflow,apark263/tensorflow,gautam1858/tensorflow,annarev/tensorflow,ghchinoy/tensorflow,dongjoon-hyun/tensorflow,apark263/tensorflow,gunan/tensorflow,aselle/tensorflow,hfp/tensorflow-xsmm,Intel-tensorflow/tensorflow,sarvex/tensorflow,dongjoon-hyun/tensorflow,xzturn/tensorflow,Intel-tensorflow/tensorflow,alshedivat/tensorflow,ppwwyyxx/tensorflow,karllessard/tensorflow,freedomtan/tensorflow,caisq/tensorflow,dancingdan/tensorflow,tensorflow/tensorflow,petewarden/tensorflow,ageron/tensorflow,manipopopo/tensorflow,gautam1858/tensorflow,girving/tensorflow,xodus7/tensorflow,Intel-Corporation/tensorflow,alshedivat/tensorflow,sarvex/tensorflow,kevin-coder/tensorflow-fork,ppwwyyxx/tensorflow,caisq/tensorflow,caisq/tensorflow,seanli9jan/tensorflow,dongjoon-hyun/tensorflow,kobejean/tensorflow,cxxgtxy/tensorflow,kevin-coder/tensorflow-fork,tensorflow/tensorflow,gunan/tensorflow,xodus7/tensorflow,ghchinoy/tensorflow,cxxgtxy/tensorflow,davidzchen/tensorflow,AnishShah/tensorflow,cxxgtxy/tensorflow,DavidNorman/tensorflow,aam-at/tensorflow,xodus7/tensorflow,Intel-tensorflow/tensorflow,freedomtan/tensorflow,sarvex/tensorflow,aldian/tensorflow,gunan/tensorflow,renyi533/tensorflow,jendap/tensorflow,frreiss/tensorflow-fred,aldian/tensorflow,girving/tensorflow,brchiu/tensorflow,ageron/tensorflow,yongtang/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,alshedivat/tensorflow,jhseu/tensorflow,AnishShah/tensorflow,davidzchen/tensorflow,snnn/tensorflow,seanli9jan/tensorflow,jbedorf/tensorflow,jbedorf/tensorflow,seanli9jan/tensorflow,annarev/tensorflow,seanli9jan/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,manipopopo/tensorflow,jalexvig/tensorflow,xzturn/tensorflow,gautam1858/tensorflow,theflofly/tensorflow,chemelnucfin/tensorflow,yongtang/tensorflow,freedomtan/tensorflow,paolodedios/tensorflow,tensorflow/tensorflow-pywrap_saved_model,annarev/tensorflow,theflofly/tensorflow,alsrgv/tensorflow,aselle/tensorflow,aselle/tensorflow,frreiss/tensorflow-fred,gunan/tensorflow,freedomtan/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,paolodedios/tensorflow,jendap/tensorflow,Bismarrck/tensorflow,davidzchen/tensorflow,alshedivat/tensorflow,kobejean/tensorflow,sarvex/tensorflow,seanli9jan/tensorflow,theflofly/tensorflow,caisq/tensorflow,seanli9jan/tensorflow,seanli9jan/tensorflow,ageron/tensorflow,dancingdan/tensorflow,yongtang/tensorflow,aam-at/tensorflow,kevin-coder/tensorflow-fork,freedomtan/tensorflow,renyi533/tensorflow,Bismarrck/tensorflow,paolodedios/tensorflow,brchiu/tensorflow,ZhangXinNan/tensorflow,arborh/tensorflow,gautam1858/tensorflow,frreiss/tensorflow-fred,aselle/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,dancingdan/tensorflow,xzturn/tensorflow,ZhangXinNan/tensorflow,asimshankar/tensorflow,dancingdan/tensorflow,gunan/tensorflow,xodus7/tensorflow,frreiss/tensorflow-fred,aselle/tensorflow,ghchinoy/tensorflow,jhseu/tensorflow,AnishShah/tensorflow,ageron/tensorflow,aldian/tensorflow,jendap/tensorflow,theflofly/tensorflow,Intel-Corporation/tensorflow,alsrgv/tensorflow,kobejean/tensorflow,hfp/tensorflow-xsmm,alsrgv/tensorflow