MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / MakePyInputs

Function MakePyInputs

oneflow/extension/python/py_compute.cpp:116–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116void MakePyInputs(const UserOpDef& op_def, user_op::KernelComputeContext* ctx,
117 PyObject** py_inputs) {
118 const size_t kernel_in_num = ctx->inputs().size();
119 const size_t def_in_num = op_def.input_size();
120 CHECK_EQ(kernel_in_num, def_in_num) << "kernel input num " << kernel_in_num
121 << " not equal to definition input num " << def_in_num;
122 PyObject* py_list = PyList_New(def_in_num);
123 CHECK(py_list);
124
125 FOR_RANGE(size_t, i, 0, def_in_num) {
126 PyObject* arg = nullptr;
127 const std::string& arg_name = op_def.input(i).name();
128 VLOG(3) << "input arg_name " << arg_name;
129 // do not support multi input in one symbolic arg name
130 int32_t index = 0;
131 TensorToNumpy(ctx->Tensor4ArgNameAndIndex(arg_name, index), &arg);
132 arg = PyArray_Return(reinterpret_cast<PyArrayObject*>(arg));
133 PyList_SetItem(py_list, i, arg);
134 }
135 *py_inputs = Py_BuildValue("(N)", py_list);
136 CHECK(*py_inputs);
137}
138
139void GetPyOutputs(const UserOpDef& op_def, user_op::KernelComputeContext* ctx,
140 PyObject* py_outputs) {

Callers 1

PyComputeFunction · 0.85

Calls 2

sizeMethod · 0.45
input_sizeMethod · 0.45

Tested by

no test coverage detected