This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # cinn/frontend/net_builder_test.cc # cinn/hlir/op/contrib/CMakeLists.txt
- Loading branch information
Showing
68 changed files
with
2,897 additions
and
384 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) 2022 CINN Authors. All Rights Reserved. | ||
// | ||
// 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. | ||
|
||
syntax ="proto3"; | ||
|
||
package cinn.auto_schedule.proto; | ||
|
||
message TuningRecord { | ||
string task_key = 1; | ||
double execution_cost = 2; | ||
} |
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 |
---|---|---|
@@ -1,13 +1,7 @@ | ||
core_gather_headers() | ||
|
||
gather_srcs(cinnapi_src SRCS cost_model.cc) | ||
gather_srcs(cinnapi_src SRCS xgb_cost_model.cc expr_cost_model.cc feature.cc feature_extractor.cc) | ||
|
||
set(Python_VIRTUALENV FIRST) | ||
find_package(PythonInterp ${PY_VERSION} REQUIRED) | ||
find_package(PythonLibs ${PY_VERSION} REQUIRED) | ||
|
||
if (WITH_TESTING) | ||
cc_test(test_cost_model SRCS cost_model_test.cc cost_model.cc DEPS pybind gtest_main) | ||
|
||
target_link_libraries(test_cost_model ${PYTHON_LIBRARIES}) | ||
endif() | ||
cc_test(test_xgb_cost_model SRCS xgb_cost_model_test.cc DEPS cinncore) | ||
cc_test(test_feature_extractor SRCS feature_extractor_test.cc DEPS cinncore) | ||
cc_test(test_feature SRCS feature_test.cc DEPS cinncore) |
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,77 @@ | ||
// Copyright (c) 2022 CINN Authors. All Rights Reserved. | ||
// | ||
// 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. | ||
|
||
#include "cinn/auto_schedule/cost_model/expr_cost_model.h" | ||
|
||
#include <glog/logging.h> | ||
|
||
#include <atomic> | ||
#include <vector> | ||
|
||
#include "cinn/auto_schedule/cost_model/feature.h" | ||
#include "cinn/auto_schedule/cost_model/feature_extractor.h" | ||
#include "cinn/auto_schedule/search_space/search_state.h" | ||
#include "cinn/common/target.h" | ||
#include "cinn/ir/ir_schedule.h" | ||
|
||
namespace cinn { | ||
namespace auto_schedule { | ||
|
||
float ExprCostModel::Predict(const ir::ModuleExpr& sample, const common::Target& target) const { | ||
if (trained_times_.load() == 0) { | ||
return SearchState::NOT_INIT_COST; | ||
} | ||
FeatureExtractor extractor; | ||
Feature feature = extractor.Extract(sample, target); | ||
std::vector<float> feature_numbers = feature.ToFixedSizeVector(); | ||
std::vector<float> pred = XgbCostModel::Predict({feature_numbers}); | ||
return pred[0]; | ||
} | ||
|
||
void ExprCostModel::Train(const std::vector<const ir::ModuleExpr*>& samples, | ||
const std::vector<float>& labels, | ||
const common::Target& target) { | ||
trained_times_.store(1); | ||
size_t total_size = samples.size(); | ||
CHECK_EQ(total_size, labels.size()) << "Samples must have same size as labels"; | ||
std::vector<std::vector<float>> train_feature_numbers(total_size); | ||
FeatureExtractor extractor; | ||
for (size_t i = 0; i < total_size; ++i) { | ||
CHECK(samples[i] != nullptr) << "Train samples cannot be nullptr"; | ||
Feature feature = extractor.Extract(*samples[i], target); | ||
train_feature_numbers[i] = feature.ToFixedSizeVector(); | ||
} | ||
|
||
XgbCostModel::Train(train_feature_numbers, labels); | ||
} | ||
|
||
void ExprCostModel::Update(const std::vector<const ir::ModuleExpr*>& samples, | ||
const std::vector<float>& labels, | ||
const common::Target& target) { | ||
++trained_times_; | ||
size_t total_size = samples.size(); | ||
CHECK_EQ(total_size, labels.size()) << "Samples must have same size as labels"; | ||
std::vector<std::vector<float>> train_feature_numbers(total_size); | ||
FeatureExtractor extractor; | ||
for (size_t i = 0; i < total_size; ++i) { | ||
CHECK(samples[i] != nullptr) << "Train samples cannot be nullptr"; | ||
Feature feature = extractor.Extract(*samples[i], target); | ||
train_feature_numbers[i] = feature.ToFixedSizeVector(); | ||
} | ||
|
||
XgbCostModel::Update(train_feature_numbers, labels); | ||
} | ||
|
||
} // namespace auto_schedule | ||
} // namespace cinn |
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,45 @@ | ||
// Copyright (c) 2022 CINN Authors. All Rights Reserved. | ||
// | ||
// 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. | ||
|
||
#pragma once | ||
|
||
#include <atomic> | ||
#include <vector> | ||
|
||
#include "cinn/auto_schedule/cost_model/xgb_cost_model.h" | ||
#include "cinn/ir/ir_schedule.h" | ||
|
||
namespace cinn { | ||
namespace auto_schedule { | ||
|
||
/** | ||
* A C++ cost model which trains and predicts on ir::Expr | ||
* | ||
*/ | ||
class ExprCostModel : public XgbCostModel { | ||
public: | ||
float Predict(const ir::ModuleExpr& sample, const common::Target& target) const; | ||
void Train(const std::vector<const ir::ModuleExpr*>& samples, | ||
const std::vector<float>& labels, | ||
const common::Target& target); | ||
void Update(const std::vector<const ir::ModuleExpr*>& samples, | ||
const std::vector<float>& labels, | ||
const common::Target& target); | ||
|
||
private: | ||
std::atomic<int> trained_times_{0}; | ||
}; | ||
|
||
} // namespace auto_schedule | ||
} // namespace cinn |
Oops, something went wrong.