-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: accelerate JIT compilation speed (#618)
Current JIT compilation is slow because we rely on a huge header `<torch/extension.h>` which is too heavy for our use case. This PR refactors the codebase to only include necessary headers for pybind, and moves most of torch runtime API calls from C++ to python. The compilation time was reduced from 48 seconds to 18 seconds for lightweight operators such as norm.
- Loading branch information
Showing
76 changed files
with
2,420 additions
and
2,101 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
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,48 @@ | ||
/* | ||
* Copyright (c) 2024 by FlashInfer team. | ||
* | ||
* 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 FLASHINFER_EXCEPTION_H_ | ||
#define FLASHINFER_EXCEPTION_H_ | ||
|
||
#include <exception> | ||
#include <sstream> | ||
|
||
namespace flashinfer { | ||
|
||
class Error : public std::exception { | ||
private: | ||
std::string message_; | ||
|
||
public: | ||
Error(const std::string& func, const std::string& file, int line, const std::string& message) { | ||
std::ostringstream oss; | ||
oss << "Error in function '" << func << "' " | ||
<< "at " << file << ":" << line << ": " << message; | ||
message_ = oss.str(); | ||
} | ||
|
||
virtual const char* what() const noexcept override { return message_.c_str(); } | ||
}; | ||
|
||
#define FLASHINFER_ERROR(message) throw Error(__FUNCTION__, __FILE__, __LINE__, message) | ||
|
||
#define FLASHINFER_CHECK(condition, message) \ | ||
if (!(condition)) { \ | ||
FLASHINFER_ERROR(message); \ | ||
} | ||
|
||
} // namespace flashinfer | ||
|
||
#endif // FLASHINFER_EXCEPTION_H_ |
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
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
prune */__pycache__ | ||
prune csrc | ||
prune csrc_aot | ||
exclude aot_setup.py | ||
exclude setup.py | ||
|
||
|
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
Oops, something went wrong.