forked from apache/mxnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* impl - FFi for linalg op (apache#17795)
* fix - cpplint * impl - benchmark ffi for ops * rm - FFI for ops with param * fix - makefile * fix - not include unordered_map and use num_inputs * ci - compiler error * fix - change cholesky interface Co-authored-by: Ubuntu <[email protected]>
- Loading branch information
1 parent
886b90b
commit bc1decd
Showing
21 changed files
with
440 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/*! | ||
* \file np_eigvals.cc | ||
* \brief Implementation of the API of functions in src/operator/numpy/linalg/np_eigvals.cc | ||
*/ | ||
#include <mxnet/api_registry.h> | ||
#include <mxnet/runtime/packed_func.h> | ||
#include "../../utils.h" | ||
#include "../../../../operator/numpy/linalg/np_eigvals-inl.h" | ||
|
||
namespace mxnet { | ||
|
||
MXNET_REGISTER_API("_npi.eigvals") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_eigvals"); | ||
nnvm::NodeAttrs attrs; | ||
attrs.op = op; | ||
int num_inputs = 1; | ||
int num_outputs = 0; | ||
NDArray* inputs[] = {args[0].operator mxnet::NDArray*()}; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, nullptr); | ||
*ret = reinterpret_cast<mxnet::NDArray*>(ndoutputs[0]); | ||
}); | ||
|
||
MXNET_REGISTER_API("_npi.eigvalsh") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_eigvalsh"); | ||
nnvm::NodeAttrs attrs; | ||
op::EigvalshParam param; | ||
param.UPLO = *((args[1].operator std::string()).c_str()); | ||
attrs.parsed = param; | ||
attrs.op = op; | ||
SetAttrDict<op::EigvalshParam>(&attrs); | ||
int num_inputs = 1; | ||
int num_outputs = 0; | ||
NDArray* inputs[] = {args[0].operator mxnet::NDArray*()}; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, nullptr); | ||
*ret = reinterpret_cast<mxnet::NDArray*>(ndoutputs[0]); | ||
}); | ||
|
||
} // namespace mxnet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/*! | ||
* \file np_inv.cc | ||
* \brief Implementation of the API of functions in src/operator/tensor/la_op.cc | ||
*/ | ||
#include <mxnet/api_registry.h> | ||
#include <mxnet/runtime/packed_func.h> | ||
#include "../../utils.h" | ||
|
||
namespace mxnet { | ||
|
||
MXNET_REGISTER_API("_npi.inv") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_inv"); | ||
nnvm::NodeAttrs attrs; | ||
attrs.op = op; | ||
int num_inputs = 1; | ||
int num_outputs = 0; | ||
NDArray* inputs[] = {args[0].operator mxnet::NDArray*()}; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, nullptr); | ||
*ret = reinterpret_cast<mxnet::NDArray*>(ndoutputs[0]); | ||
}); | ||
|
||
} // namespace mxnet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/*! | ||
* \file np_pinv.cc | ||
* \brief Implementation of the API of functions in src/operator/numpy/linalg/np_pinv.cc | ||
*/ | ||
#include <mxnet/api_registry.h> | ||
#include <mxnet/runtime/packed_func.h> | ||
#include "../../utils.h" | ||
#include "../../../../operator/numpy/linalg/np_pinv-inl.h" | ||
|
||
namespace mxnet { | ||
|
||
inline static void _npi_pinv(runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_pinv"); | ||
op::PinvParam param; | ||
nnvm::NodeAttrs attrs; | ||
param.hermitian = args[2].operator bool(); | ||
attrs.parsed = param; | ||
attrs.op = op; | ||
SetAttrDict<op::PinvParam>(&attrs); | ||
int num_inputs = 2; | ||
int num_outputs = 0; | ||
NDArray* inputs[] = {args[0].operator mxnet::NDArray*(), args[1].operator mxnet::NDArray*()}; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, nullptr); | ||
*ret = reinterpret_cast<mxnet::NDArray*>(ndoutputs[0]); | ||
} | ||
|
||
inline static void _npi_pinv_scalar_rcond(runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_pinv_scalar_rcond"); | ||
op::PinvScalarRcondParam param; | ||
nnvm::NodeAttrs attrs; | ||
param.rcond = args[1].operator double(); | ||
param.hermitian = args[2].operator bool(); | ||
attrs.parsed = param; | ||
attrs.op = op; | ||
SetAttrDict<op::PinvScalarRcondParam>(&attrs); | ||
int num_inputs = 1; | ||
int num_outputs = 0; | ||
NDArray* inputs[] = {args[0].operator mxnet::NDArray*()}; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, nullptr); | ||
*ret = reinterpret_cast<mxnet::NDArray*>(ndoutputs[0]); | ||
} | ||
|
||
MXNET_REGISTER_API("_npi.pinv") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
if (args[1].type_code() == kDLFloat || args[1].type_code() == kDLInt) { | ||
_npi_pinv_scalar_rcond(args, ret); | ||
} else { | ||
_npi_pinv(args, ret); | ||
} | ||
}); | ||
|
||
} // namespace mxnet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/*! | ||
* \file np_potrf.cc | ||
* \brief Implementation of the API of functions in src/operator/numpy/linalg/np_potrf.cc | ||
*/ | ||
#include <mxnet/api_registry.h> | ||
#include <mxnet/runtime/packed_func.h> | ||
#include "../../utils.h" | ||
#include "../../../../operator/numpy/linalg/np_potrf-inl.h" | ||
|
||
namespace mxnet { | ||
|
||
MXNET_REGISTER_API("_npi.cholesky") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_cholesky"); | ||
nnvm::NodeAttrs attrs; | ||
op::LaCholeskyParam param; | ||
param.lower = args[1].operator bool(); | ||
attrs.parsed = param; | ||
attrs.op = op; | ||
SetAttrDict<op::LaCholeskyParam>(&attrs); | ||
int num_inputs = 1; | ||
int num_outputs = 0; | ||
NDArray* inputs[] = {args[0].operator mxnet::NDArray*()}; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, nullptr); | ||
*ret = reinterpret_cast<mxnet::NDArray*>(ndoutputs[0]); | ||
}); | ||
|
||
} // namespace mxnet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/*! | ||
* \file np_solve.cc | ||
* \brief Implementation of the API of functions in src/operator/numpy/linalg/np_solve.cc | ||
*/ | ||
#include <mxnet/api_registry.h> | ||
#include <mxnet/runtime/packed_func.h> | ||
#include "../../utils.h" | ||
|
||
namespace mxnet { | ||
|
||
MXNET_REGISTER_API("_npi.solve") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_solve"); | ||
nnvm::NodeAttrs attrs; | ||
attrs.op = op; | ||
int num_inputs = 2; | ||
int num_outputs = 0; | ||
NDArray* inputs[] = {args[0].operator mxnet::NDArray*(), args[1].operator mxnet::NDArray*()}; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, nullptr); | ||
*ret = reinterpret_cast<mxnet::NDArray*>(ndoutputs[0]); | ||
}); | ||
|
||
} // namespace mxnet |
Oops, something went wrong.