【in C++】No OpKernel was registered to support Op 'PyFunc' used by {{node PyFunc}}with these attrs: [Tin=[], Tout=[DT_FLOAT], token="pyfunc_0"] Registered devices: [CPU, XLA_CPU] Registered kernels:   <no registered kernels>           [[PyFunc]]
Java Inference, the same question。 Hi @chuanshanjia ,

TF1.x versions are not supported anymore. Will you upgrade it to latest TF version and let us know if any issue there. Thanks! Hi @chuanshanjia ,

I have checked with TF1.15V and there kernels found registered for only GPU devices as per below code.
https://github.com/tensorflow/tensorflow/blob/590d6eef7e91a6a7392c8ffffb7b58f2e0c8bc6b/tensorflow/python/lib/core/py_func.cc#L398

Now in TF2.14v I can see that kernels are registered for all as DEVICE_DEFAULT.Here it should work for all devices.

https://github.com/tensorflow/tensorflow/blob/4dacf3f368eb7965e9b5c3bbdd5193986081c3b2/tensorflow/python/lib/core/py_func.cc#L422

You can see the list of `dtypes` supported in TF2.14 for the Op **PyFunc** here.

https://github.com/tensorflow/tensorflow/blob/4dacf3f368eb7965e9b5c3bbdd5193986081c3b2/tensorflow/python/lib/core/py_func.cc#L413-L420


You can test the code with TF2.14v and let us know if you still have any problem.Thanks! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62066">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62066">No</a>

### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

binary

### TensorFlow version

tf 1.15.0

### Custom code

Yes

### OS platform and distribution

Linux

### Mobile device

15001379103

### Python version

_No response_

### Bazel version

4.2.1

### GCC/compiler version

4.8.5

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

method: C API
version: 1.15.0
package link:https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.15.0.tar.gz





### Standalone code to reproduce the issue

```shell
#include "app/federal/model.hpp"
#include <iostream>
#include <fstream>

namespace xcxxx {
    /**
     * Print Tensorflow version
    */
  void Model::PrintTfVersion() {
    std::cout << "Hello from TensorFlow C library version \n" <<  TF_Version() << std::endl;
  }

  void NoOpDeallocator(void* data, size_t a, void* b) {
  }

  void DeallocateBuffer(void* data, size_t) {
    std::free(data);
  }

  TF_Buffer* ReadBufferFromFile(std::string file) {
    std::ifstream f(file, std::ios::binary);
    if (f.fail() || !f.is_open()) {
      return nullptr;
    }

    f.seekg(0, std::ios::end);
    const auto fsize = f.tellg();
    f.seekg(0, std::ios::beg);

    if (fsize < 1) {
      f.close();
      return nullptr;
    }

    char* data = static_cast<char*>(std::malloc(fsize));
    f.read(data, fsize);
    f.close();

    TF_Buffer* buf = TF_NewBuffer();
    buf->data = data;
    buf->length = fsize;
    buf->data_deallocator = DeallocateBuffer;
    return buf;
  }
    /**
     * Init Model Instance
    */
   bool Model::Init(std::string model_file) {
    try {

        // create new graph
        TF_Buffer* buffer = ReadBufferFromFile(model_file);
        if (buffer == nullptr) {
          std::cout << "code:10000" <<  ", msg: " <<  "Error creating the session from  the given model path!"<< std::endl;
          return false;
        }
        TF_ImportGraphDefOptions* opts = TF_NewImportGraphDefOptions();
        TF_Status* status = TF_NewStatus();

        m_graph_ = TF_NewGraph();
        TF_GraphImportGraphDef(m_graph_, buffer, opts, status);
        TF_DeleteImportGraphDefOptions(opts);
        TF_DeleteBuffer(buffer);
        if (TF_GetCode(status) != TF_OK) {
            std::cout << "code:10001" <<  ", msg: " << TF_Message(status) << std::endl;
            TF_DeleteGraph(m_graph_);
            m_graph_ = nullptr;
            return false;
        }
        TF_DeleteStatus(status);

        // create new session
        status = TF_NewStatus();
        TF_SessionOptions* options = TF_NewSessionOptions();
        m_session_ = TF_NewSession(m_graph_, options, status);
        TF_DeleteSessionOptions(options);
        if (TF_GetCode(status) != TF_OK) {
            std::cout << "code:10002" <<  ", msg: " << TF_Message(status) << std::endl;
            return false;
        }
        TF_DeleteStatus(status);
        std::cout << "code:0" <<  ", msg: load model suc!^_^" << std::endl;
    
    } catch (std::exception& e) {
        std::cout << "code:10003" <<  ", msg: model init.Tf load fail!" << std::endl;
        return false;
    }

    return true;
   }


  /**
     * Init Model Instance
    */
   bool Model::InitV2(std::string model_file) {
    try {
      TF_Buffer* buffer = ReadBufferFromFile(model_file);
      if (buffer == nullptr) {
        std::cout << "code:10000" <<  ", msg: model init.Tf load fail!" << std::endl;
      }
      TF_Status* status = TF_NewStatus();
      TF_ImportGraphDefOptions* opts = TF_NewImportGraphDefOptions();

      m_graph_ = TF_NewGraph();
      TF_GraphImportGraphDef(m_graph_, buffer, opts, status);
      TF_DeleteImportGraphDefOptions(opts);
      TF_DeleteBuffer(buffer);
      if (TF_GetCode(status) != TF_OK) {
        TF_DeleteGraph(m_graph_);
        m_graph_ = nullptr;
      }
      TF_DeleteStatus(status);

      // create session from graph
      status = TF_NewStatus();
      TF_SessionOptions* options = TF_NewSessionOptions();
      m_session_ = TF_NewSession(m_graph_, options, status);
      TF_DeleteSessionOptions(options);
    } catch (std::exception& e) {
        std::cout << "code:10003" <<  ", msg: model init.Tf load fail!" << std::endl;
        return false;
    }

    return true;
   }

   /**
    *  infer
   */
  std::vector<float> Model::Infer(std::vector<float> input_data) {
    std::vector<float> ret;

    //****** 1、Define graph inputs/outputs
    // std::string train_input_name = "top_model/inputs:0";
    std::string train_input_name = "top_model/inputs";
    // std::string train_output_name = "top_model/outputs:0";
    std::string train_output_name = "top_model/outputs";

    // Define graph inputs
    uint16_t gr_input_nums = 1;
    TF_Output* inputs = (TF_Output*)malloc(sizeof(TF_Output) * gr_input_nums);
    TF_Output input0 = {TF_GraphOperationByName(m_graph_, train_input_name.c_str()), 0};


    size_t pos = 0;
    uint16_t i = 0;
    TF_Operation* oper;
    
    while ((oper = TF_GraphNextOperation(m_graph_, &pos)) != nullptr) {
      std::cout << "index:" << i << ", graphname:" << TF_OperationName(oper) << std::endl;
      i++;
    }

    if (nullptr == input0.oper) {
      std::cout << "code:20000" <<  ", msg: Define graph inputs failure" << std::endl;
      return ret;
    }
    inputs[0] = input0;

    // Define graph outpus
    uint16_t gr_output_nums = 1;
    TF_Output* outputs = (TF_Output*)malloc(sizeof(TF_Output) * gr_output_nums);
    TF_Output output0 = {TF_GraphOperationByName(m_graph_, train_output_name.c_str()), 0};
    if (nullptr == output0.oper) {
      std::cout << "code:20001" <<  ", msg: Define graph outputs failure" << std::endl;
      return ret;
    }
    outputs[0] = output0;


    //****** 2、Create input tensor(s) and populate with feature
    TF_Tensor** input_values = (TF_Tensor**)malloc(sizeof(TF_Tensor*) * gr_input_nums);
    int16_t num_dims = 1;
    int64_t dims[] = {1};
    float_t* data = &input_data[0];
    TF_Tensor* float_tensor = TF_NewTensor(TF_FLOAT, dims, num_dims, data, sizeof(TF_FLOAT), &NoOpDeallocator, 0);
    if (nullptr == float_tensor) {
      std::cout << "code:20002" <<  ", msg: allocate failure" << std::endl;
      return ret;
    }
    input_values[0] = float_tensor;

    TF_Tensor** output_values = (TF_Tensor**)malloc(sizeof(TF_Tensor*) * gr_output_nums);

    //****** 3、Run the session
    TF_Status* status = TF_NewStatus();
    TF_SessionRun(
      m_session_, 
      nullptr, 
      // Input tensors
      inputs, input_values, gr_input_nums,
      // Output tensors
      outputs, output_values, gr_output_nums,
      // Target operations
      nullptr, 0,
      // RunMedata
      nullptr,
      // Output status
      status
    );

    if (TF_OK != TF_GetCode(status)) {
      std::cout << "code:20003" <<  ", msg: infer failure!\nstatus:" << TF_Message(status) << std::endl;
      return ret;
    }
    std::cout << "code:0" <<  ", msg: infer suc!^_^" << std::endl;

    //****** 4、Output the result
    void* buff = TF_TensorData(output_values[0]);
    float* offsets = (float*)buff;
    std::cout << "infer result:" << offsets[0] << std::endl;


    TF_DeleteStatus(status);
    return ret;
  }

}
```


### Relevant log output

```shell
No OpKernel was registered to support Op 'PyFunc' used by {{node PyFunc}}with these attrs: [Tin=[], Tout=[DT_FLOAT], token="pyfunc_0"]
Registered devices: [CPU, XLA_CPU]
Registered kernels:
  <no registered kernels>

         [[PyFunc]]
```
