!5058 remove backend/session dependency on python
Merge pull request !5058 from xychow/remove-backend-py-dependency-1pull/5058/MERGE
commit
9a5e074c48
@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_CCSRC_PIPELINE_JIT_RESOURCE_BASE_H_
|
||||
#define MINDSPORE_CCSRC_PIPELINE_JIT_RESOURCE_BASE_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
#include "utils/any.h"
|
||||
#include "ir/manager.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace pipeline {
|
||||
|
||||
class ResourceBase {
|
||||
public:
|
||||
ResourceBase() { manager_ = MakeManager(); }
|
||||
|
||||
virtual ~ResourceBase() = default;
|
||||
|
||||
FuncGraphManagerPtr manager() { return manager_; }
|
||||
// set a manager defined outside which will not manage the graphs.
|
||||
void set_manager(const FuncGraphManagerPtr &manager) { manager_ = manager; }
|
||||
|
||||
std::unordered_map<std::string, Any> &results() { return results_; }
|
||||
|
||||
void SetResult(const std::string &key, const Any &value) { results_[key] = value; }
|
||||
|
||||
Any GetResult(const std::string &key) {
|
||||
if (results_.count(key) == 0) {
|
||||
MS_LOG(EXCEPTION) << "this key is not in resource list:" << key;
|
||||
}
|
||||
return results_[key];
|
||||
}
|
||||
|
||||
bool HasResult(const std::string &key) const { return results_.count(key) != 0; }
|
||||
|
||||
std::unordered_map<std::string, Any> results_;
|
||||
|
||||
protected:
|
||||
FuncGraphManagerPtr manager_;
|
||||
};
|
||||
|
||||
using ResourceBasePtr = std::shared_ptr<pipeline::ResourceBase>;
|
||||
|
||||
} // namespace pipeline
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_CCSRC_PIPELINE_JIT_RESOURCE_BASE_H_
|
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
#ifndef PYBIND_API_GIL_SCOPED_LONG_RUNNING_H_
|
||||
#define PYBIND_API_GIL_SCOPED_LONG_RUNNING_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "pybind11/pybind11.h"
|
||||
|
||||
#include "utils/scoped_long_running.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
namespace mindspore {
|
||||
class GilScopedLongRunningHook : public ScopedLongRunningHook {
|
||||
public:
|
||||
void Enter() override { release_ = std::make_unique<py::gil_scoped_release>(); }
|
||||
void Leave() override { release_ = nullptr; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<py::gil_scoped_release> release_;
|
||||
};
|
||||
} // namespace mindspore
|
||||
#endif // PYBIND_API_GIL_SCOPED_LONG_RUNNING_H_
|
@ -1,45 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
#ifndef MINDSPORE_CCSRC_UTILS_BASE_REF_EXTENDS_H_
|
||||
#define MINDSPORE_CCSRC_UTILS_BASE_REF_EXTENDS_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "pybind_api/ir/base_ref_py.h"
|
||||
#include "base/base_ref.h"
|
||||
|
||||
namespace mindspore {
|
||||
class PyObjectRef : public BaseRef {
|
||||
public:
|
||||
explicit PyObjectRef(const py::object &py_object) : object_(py_object) {}
|
||||
explicit PyObjectRef(const py::tuple &tuple_obj) : object_(tuple_obj) {}
|
||||
|
||||
~PyObjectRef() override = default;
|
||||
|
||||
std::shared_ptr<Base> copy() const override { return std::make_shared<PyObjectRef>(object_); }
|
||||
MS_DECLARE_PARENT(PyObjectRef, BaseRef)
|
||||
|
||||
uint32_t type() const override { return tid(); }
|
||||
std::string ToString() const override { return py::str(object_); }
|
||||
bool operator==(const BaseRef &other) const override;
|
||||
bool operator==(const PyObjectRef &other) const;
|
||||
|
||||
py::object object_;
|
||||
};
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_CCSRC_UTILS_BASE_REF_EXTENDS_H_
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue