tokenspeed-deepjit 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tokenspeed_deepjit-0.1.0/MANIFEST.in +4 -0
- tokenspeed_deepjit-0.1.0/PKG-INFO +79 -0
- tokenspeed_deepjit-0.1.0/README.md +67 -0
- tokenspeed_deepjit-0.1.0/pyproject.toml +30 -0
- tokenspeed_deepjit-0.1.0/setup.cfg +4 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/__init__.py +27 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/cmake/deep_jitConfig.cmake +17 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/cmake/deep_jitConfigVersion.cmake +11 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/backend/ascend/backend.hpp +185 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/backend/ascend/device.hpp +79 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/backend/ascend/driver.hpp +37 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/backend/ascend/kernel.hpp +236 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/backend/ascend/options.hpp +159 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/backend/cuda/backend.hpp +220 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/backend/cuda/device.hpp +83 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/backend/cuda/driver.hpp +44 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/backend/cuda/kernel.hpp +186 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/backend/cuda/options.hpp +234 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/cache/disk.hpp +136 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/cache/memory.hpp +24 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/python_api.hpp +22 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/runtime/config.hpp +66 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/runtime/runtime.hpp +108 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/utils/command.hpp +39 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/utils/env.hpp +86 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/utils/exception.hpp +197 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/utils/filesystem.hpp +120 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/utils/gil.hpp +24 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/utils/hash.hpp +44 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/utils/json.hpp +131 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/utils/lazy.hpp +68 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/utils/no_ref_ptr.hpp +10 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/utils/parser.hpp +123 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/utils/str.hpp +28 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit/include/deep_jit/utils/uuid.hpp +25 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit.egg-info/PKG-INFO +79 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit.egg-info/SOURCES.txt +39 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit.egg-info/dependency_links.txt +1 -0
- tokenspeed_deepjit-0.1.0/src/tokenspeed_deepjit.egg-info/top_level.txt +1 -0
- tokenspeed_deepjit-0.1.0/tests/CMakeLists.txt +7 -0
- tokenspeed_deepjit-0.1.0/tests/smoke_headers.cc +26 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tokenspeed-deepjit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python packaging for the header-only DeepJIT C++ library.
|
|
5
|
+
Author: TokenSpeed maintainers
|
|
6
|
+
Project-URL: Homepage, https://github.com/deepseek-ai/DeepJIT
|
|
7
|
+
Project-URL: Source, https://github.com/deepseek-ai/DeepJIT
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: C++
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# tokenspeed-deepjit
|
|
14
|
+
|
|
15
|
+
Python packaging for the header-only
|
|
16
|
+
[deepseek-ai/DeepJIT](https://github.com/deepseek-ai/DeepJIT) C++20 library.
|
|
17
|
+
The `tokenspeed-deepjit` distribution vendors the headers from upstream commit
|
|
18
|
+
[`8b3ef868705a3792cc1a14ab570b539f72fd3d94`](https://github.com/deepseek-ai/DeepJIT/commit/8b3ef868705a3792cc1a14ab570b539f72fd3d94)
|
|
19
|
+
and provides Python and CMake helpers for locating them.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install tokenspeed-deepjit
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The wheel is platform-independent because DeepJIT is header-only. Applications
|
|
28
|
+
still need the device toolchain and libraries required by the selected backend.
|
|
29
|
+
CUDA consumers need CUDA headers 12.4 or newer, NVCC 12.9 or newer, and PyTorch
|
|
30
|
+
with CUDA support. Ascend consumers need the CANN compiler and headers, ACL, and
|
|
31
|
+
`torch_npu`. Pybind11 is also required when exposing DeepJIT through a Python
|
|
32
|
+
extension.
|
|
33
|
+
|
|
34
|
+
## Python helpers
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import tokenspeed_deepjit
|
|
38
|
+
|
|
39
|
+
print(tokenspeed_deepjit.include_dir())
|
|
40
|
+
print(tokenspeed_deepjit.cmake_prefix_path())
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The distribution does not install a `deep_jit` Python import package. The
|
|
44
|
+
upstream import package is empty; omitting it avoids conflicts with extensions
|
|
45
|
+
that embed DeepJIT.
|
|
46
|
+
|
|
47
|
+
## CMake usage
|
|
48
|
+
|
|
49
|
+
```cmake
|
|
50
|
+
find_package(Python COMPONENTS Interpreter REQUIRED)
|
|
51
|
+
execute_process(
|
|
52
|
+
COMMAND "${Python_EXECUTABLE}" -c
|
|
53
|
+
"import tokenspeed_deepjit; print(tokenspeed_deepjit.cmake_prefix_path())"
|
|
54
|
+
OUTPUT_VARIABLE tokenspeed_deepjit_ROOT
|
|
55
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
56
|
+
COMMAND_ERROR_IS_FATAL ANY
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
list(PREPEND CMAKE_PREFIX_PATH "${tokenspeed_deepjit_ROOT}")
|
|
60
|
+
find_package(deep_jit CONFIG REQUIRED)
|
|
61
|
+
target_link_libraries(my_target PRIVATE deep_jit::deep_jit)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The imported target requests C++20 for C++ sources. CUDA projects must also set
|
|
65
|
+
`CUDA_STANDARD 20` or pass the equivalent standard flag to NVCC.
|
|
66
|
+
|
|
67
|
+
## Local build
|
|
68
|
+
|
|
69
|
+
Populate the upstream headers before building:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
git clone https://github.com/deepseek-ai/DeepJIT.git /tmp/DeepJIT
|
|
73
|
+
git -C /tmp/DeepJIT checkout 8b3ef868705a3792cc1a14ab570b539f72fd3d94
|
|
74
|
+
./prepare_headers.sh /tmp/DeepJIT
|
|
75
|
+
python -m build
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
See the [upstream documentation](https://github.com/deepseek-ai/DeepJIT) for
|
|
79
|
+
the runtime API and backend integration details.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# tokenspeed-deepjit
|
|
2
|
+
|
|
3
|
+
Python packaging for the header-only
|
|
4
|
+
[deepseek-ai/DeepJIT](https://github.com/deepseek-ai/DeepJIT) C++20 library.
|
|
5
|
+
The `tokenspeed-deepjit` distribution vendors the headers from upstream commit
|
|
6
|
+
[`8b3ef868705a3792cc1a14ab570b539f72fd3d94`](https://github.com/deepseek-ai/DeepJIT/commit/8b3ef868705a3792cc1a14ab570b539f72fd3d94)
|
|
7
|
+
and provides Python and CMake helpers for locating them.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install tokenspeed-deepjit
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The wheel is platform-independent because DeepJIT is header-only. Applications
|
|
16
|
+
still need the device toolchain and libraries required by the selected backend.
|
|
17
|
+
CUDA consumers need CUDA headers 12.4 or newer, NVCC 12.9 or newer, and PyTorch
|
|
18
|
+
with CUDA support. Ascend consumers need the CANN compiler and headers, ACL, and
|
|
19
|
+
`torch_npu`. Pybind11 is also required when exposing DeepJIT through a Python
|
|
20
|
+
extension.
|
|
21
|
+
|
|
22
|
+
## Python helpers
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
import tokenspeed_deepjit
|
|
26
|
+
|
|
27
|
+
print(tokenspeed_deepjit.include_dir())
|
|
28
|
+
print(tokenspeed_deepjit.cmake_prefix_path())
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The distribution does not install a `deep_jit` Python import package. The
|
|
32
|
+
upstream import package is empty; omitting it avoids conflicts with extensions
|
|
33
|
+
that embed DeepJIT.
|
|
34
|
+
|
|
35
|
+
## CMake usage
|
|
36
|
+
|
|
37
|
+
```cmake
|
|
38
|
+
find_package(Python COMPONENTS Interpreter REQUIRED)
|
|
39
|
+
execute_process(
|
|
40
|
+
COMMAND "${Python_EXECUTABLE}" -c
|
|
41
|
+
"import tokenspeed_deepjit; print(tokenspeed_deepjit.cmake_prefix_path())"
|
|
42
|
+
OUTPUT_VARIABLE tokenspeed_deepjit_ROOT
|
|
43
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
44
|
+
COMMAND_ERROR_IS_FATAL ANY
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
list(PREPEND CMAKE_PREFIX_PATH "${tokenspeed_deepjit_ROOT}")
|
|
48
|
+
find_package(deep_jit CONFIG REQUIRED)
|
|
49
|
+
target_link_libraries(my_target PRIVATE deep_jit::deep_jit)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The imported target requests C++20 for C++ sources. CUDA projects must also set
|
|
53
|
+
`CUDA_STANDARD 20` or pass the equivalent standard flag to NVCC.
|
|
54
|
+
|
|
55
|
+
## Local build
|
|
56
|
+
|
|
57
|
+
Populate the upstream headers before building:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
git clone https://github.com/deepseek-ai/DeepJIT.git /tmp/DeepJIT
|
|
61
|
+
git -C /tmp/DeepJIT checkout 8b3ef868705a3792cc1a14ab570b539f72fd3d94
|
|
62
|
+
./prepare_headers.sh /tmp/DeepJIT
|
|
63
|
+
python -m build
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
See the [upstream documentation](https://github.com/deepseek-ai/DeepJIT) for
|
|
67
|
+
the runtime API and backend integration details.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tokenspeed-deepjit"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python packaging for the header-only DeepJIT C++ library."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "TokenSpeed maintainers"}
|
|
13
|
+
]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: C++",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://github.com/deepseek-ai/DeepJIT"
|
|
21
|
+
Source = "https://github.com/deepseek-ai/DeepJIT"
|
|
22
|
+
|
|
23
|
+
[tool.setuptools.packages.find]
|
|
24
|
+
where = ["src"]
|
|
25
|
+
|
|
26
|
+
[tool.setuptools.package-data]
|
|
27
|
+
tokenspeed_deepjit = [
|
|
28
|
+
"cmake/*.cmake",
|
|
29
|
+
"include/deep_jit/**/*",
|
|
30
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Helpers for locating the packaged DeepJIT headers and CMake config."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__upstream_commit__",
|
|
7
|
+
"__version__",
|
|
8
|
+
"cmake_prefix_path",
|
|
9
|
+
"include_dir",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
__version__ = "0.1.0"
|
|
13
|
+
__upstream_commit__ = "8b3ef868705a3792cc1a14ab570b539f72fd3d94"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _package_root() -> Path:
|
|
17
|
+
return Path(__file__).resolve().parent
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def cmake_prefix_path() -> str:
|
|
21
|
+
"""Return the directory containing the DeepJIT CMake package config."""
|
|
22
|
+
return str(_package_root())
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def include_dir() -> str:
|
|
26
|
+
"""Return the directory containing the packaged ``deep_jit`` headers."""
|
|
27
|
+
return str(_package_root() / "include")
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
get_filename_component(_TOKENSPEED_DEEPJIT_PREFIX "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
|
|
2
|
+
set(_TOKENSPEED_DEEPJIT_INCLUDE_DIR "${_TOKENSPEED_DEEPJIT_PREFIX}/include")
|
|
3
|
+
|
|
4
|
+
if(NOT EXISTS "${_TOKENSPEED_DEEPJIT_INCLUDE_DIR}/deep_jit/runtime/runtime.hpp")
|
|
5
|
+
message(FATAL_ERROR "tokenspeed-deepjit is missing packaged DeepJIT headers")
|
|
6
|
+
endif()
|
|
7
|
+
|
|
8
|
+
if(NOT TARGET deep_jit::deep_jit)
|
|
9
|
+
add_library(deep_jit::deep_jit INTERFACE IMPORTED)
|
|
10
|
+
set_target_properties(deep_jit::deep_jit PROPERTIES
|
|
11
|
+
INTERFACE_COMPILE_FEATURES "cxx_std_20"
|
|
12
|
+
INTERFACE_INCLUDE_DIRECTORIES "${_TOKENSPEED_DEEPJIT_INCLUDE_DIR}"
|
|
13
|
+
)
|
|
14
|
+
endif()
|
|
15
|
+
|
|
16
|
+
set(deep_jit_VERSION "0.1.0")
|
|
17
|
+
set(deep_jit_FOUND TRUE)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
set(PACKAGE_VERSION "0.1.0")
|
|
2
|
+
|
|
3
|
+
if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
|
|
4
|
+
set(PACKAGE_VERSION_EXACT TRUE)
|
|
5
|
+
endif()
|
|
6
|
+
|
|
7
|
+
if(PACKAGE_FIND_VERSION VERSION_LESS_EQUAL PACKAGE_VERSION)
|
|
8
|
+
set(PACKAGE_VERSION_COMPATIBLE TRUE)
|
|
9
|
+
else()
|
|
10
|
+
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
|
11
|
+
endif()
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <filesystem>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
#include <deep_jit/backend/ascend/device.hpp>
|
|
9
|
+
#include <deep_jit/backend/ascend/kernel.hpp>
|
|
10
|
+
#include <deep_jit/backend/ascend/options.hpp>
|
|
11
|
+
#include <deep_jit/runtime/config.hpp>
|
|
12
|
+
#include <deep_jit/runtime/runtime.hpp>
|
|
13
|
+
#include <deep_jit/utils/command.hpp>
|
|
14
|
+
#include <deep_jit/utils/env.hpp>
|
|
15
|
+
#include <deep_jit/utils/exception.hpp>
|
|
16
|
+
#include <deep_jit/utils/filesystem.hpp>
|
|
17
|
+
#include <deep_jit/utils/gil.hpp>
|
|
18
|
+
#include <deep_jit/utils/hash.hpp>
|
|
19
|
+
#include <deep_jit/utils/json.hpp>
|
|
20
|
+
#include <deep_jit/utils/str.hpp>
|
|
21
|
+
|
|
22
|
+
namespace deep_jit {
|
|
23
|
+
|
|
24
|
+
class Ascend {
|
|
25
|
+
public:
|
|
26
|
+
using Device = ascend::Device;
|
|
27
|
+
using Kernel = ascend::Kernel;
|
|
28
|
+
using CompilerOptions = ascend::CompilerOptions;
|
|
29
|
+
using LaunchOptions = ascend::LaunchOptions;
|
|
30
|
+
|
|
31
|
+
struct CompilerInfo {
|
|
32
|
+
std::filesystem::path path;
|
|
33
|
+
std::string version;
|
|
34
|
+
std::filesystem::path linker_path;
|
|
35
|
+
std::string linker_version;
|
|
36
|
+
|
|
37
|
+
[[nodiscard]] std::string get_hash() const {
|
|
38
|
+
return hash::FNV1a().update(version).update(linker_version).get_hex_digest();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
[[nodiscard]] json to_json() const {
|
|
42
|
+
return json::object_t {
|
|
43
|
+
{"path", path.string()},
|
|
44
|
+
{"version", version},
|
|
45
|
+
{"linker_path", linker_path.string()},
|
|
46
|
+
{"linker_version", linker_version},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
struct Toolkit {
|
|
52
|
+
std::filesystem::path bisheng;
|
|
53
|
+
std::filesystem::path ld_lld;
|
|
54
|
+
std::filesystem::path asc_devkit_include;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
Toolkit toolkit;
|
|
58
|
+
CompilerInfo compiler_info;
|
|
59
|
+
|
|
60
|
+
explicit Ascend(const Env&)
|
|
61
|
+
: toolkit(find_ascend_toolkit()),
|
|
62
|
+
compiler_info(get_compiler_info()) {}
|
|
63
|
+
|
|
64
|
+
[[nodiscard]] CompilerInfo get_compiler_info() const {
|
|
65
|
+
return {
|
|
66
|
+
.path = toolkit.bisheng,
|
|
67
|
+
.version = call_external_command(toolkit.bisheng.string() + " --version"),
|
|
68
|
+
.linker_path = toolkit.ld_lld,
|
|
69
|
+
.linker_version = call_external_command(toolkit.ld_lld.string() + " --version"),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
void compile(const std::string& source,
|
|
74
|
+
std::filesystem::path dir,
|
|
75
|
+
const Env& env,
|
|
76
|
+
const Config& config,
|
|
77
|
+
const CompilerOptions& options) const {
|
|
78
|
+
// Release GIL to let other Python threads run
|
|
79
|
+
GilScopedRelease gil_release;
|
|
80
|
+
|
|
81
|
+
// Paths
|
|
82
|
+
dir = std::filesystem::absolute(dir).lexically_normal();
|
|
83
|
+
const auto source_path = dir / "kernel.asc";
|
|
84
|
+
const auto relocatable_path = dir / "kernel.rel.o";
|
|
85
|
+
const auto binary_path = dir / "kernel.o";
|
|
86
|
+
const bool print_compiler_command = env.get<bool>("JIT_DEBUG", false) or
|
|
87
|
+
env.get<bool>("JIT_PRINT_COMPILER_COMMAND", false);
|
|
88
|
+
|
|
89
|
+
// Write source code
|
|
90
|
+
write_file_sync(source_path, source);
|
|
91
|
+
|
|
92
|
+
// Build commands
|
|
93
|
+
std::vector<std::string> base_bisheng_args = {toolkit.bisheng.string()};
|
|
94
|
+
const auto bisheng_flags = options.get_bisheng_flags();
|
|
95
|
+
base_bisheng_args.insert(base_bisheng_args.end(), bisheng_flags.begin(), bisheng_flags.end());
|
|
96
|
+
for (const auto& include_dir: config.include_dirs)
|
|
97
|
+
base_bisheng_args.emplace_back("-I" + include_dir.string());
|
|
98
|
+
base_bisheng_args.emplace_back("-I" + toolkit.asc_devkit_include.string());
|
|
99
|
+
|
|
100
|
+
auto bisheng_args = base_bisheng_args;
|
|
101
|
+
bisheng_args.insert(bisheng_args.end(), {
|
|
102
|
+
source_path.string(),
|
|
103
|
+
"-o",
|
|
104
|
+
relocatable_path.string(),
|
|
105
|
+
});
|
|
106
|
+
const auto bisheng_command = str::join(bisheng_args);
|
|
107
|
+
|
|
108
|
+
std::vector<std::string> linker_args = {toolkit.ld_lld.string()};
|
|
109
|
+
const auto linker_flags = options.get_linker_flags();
|
|
110
|
+
linker_args.insert(linker_args.end(), linker_flags.begin(), linker_flags.end());
|
|
111
|
+
linker_args.insert(linker_args.end(), {
|
|
112
|
+
relocatable_path.string(),
|
|
113
|
+
"-o",
|
|
114
|
+
binary_path.string(),
|
|
115
|
+
});
|
|
116
|
+
const auto linker_command = str::join(linker_args);
|
|
117
|
+
|
|
118
|
+
// Compile and link
|
|
119
|
+
const auto cd_command = "cd " + dir.string() + " && ";
|
|
120
|
+
call_external_command(cd_command + bisheng_command, print_compiler_command);
|
|
121
|
+
call_external_command(cd_command + linker_command, print_compiler_command);
|
|
122
|
+
safe_remove_all(relocatable_path);
|
|
123
|
+
DJ_HOST_ASSERT(std::filesystem::is_regular_file(binary_path) and std::filesystem::file_size(binary_path) != 0,
|
|
124
|
+
"Bisheng did not produce a valid Ascend binary: {}", binary_path.string());
|
|
125
|
+
|
|
126
|
+
// Dump assembly
|
|
127
|
+
if (options.dump_asm.value_or(false)) {
|
|
128
|
+
const auto asm_dir = dir / "asm";
|
|
129
|
+
make_dirs(asm_dir);
|
|
130
|
+
auto asm_args = base_bisheng_args;
|
|
131
|
+
asm_args.insert(asm_args.end(), {
|
|
132
|
+
"-save-temps",
|
|
133
|
+
source_path.string(),
|
|
134
|
+
"-o",
|
|
135
|
+
(asm_dir / "kernel.rel.o").string(),
|
|
136
|
+
});
|
|
137
|
+
call_external_command("cd " + asm_dir.string() + " && " + str::join(asm_args),
|
|
138
|
+
print_compiler_command);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Write metadata
|
|
142
|
+
const json metadata = json::object_t {
|
|
143
|
+
{"command", bisheng_command + " && " + linker_command},
|
|
144
|
+
{"config", config.to_json()},
|
|
145
|
+
{"compiler_info", compiler_info.to_json()},
|
|
146
|
+
{"compiler_options", options.to_json()},
|
|
147
|
+
};
|
|
148
|
+
write_file_sync(dir / "meta.json", metadata.dump());
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
[[nodiscard]] static std::shared_ptr<Kernel> load(const std::filesystem::path& dir, const Env& env) {
|
|
152
|
+
return Kernel::load(dir, env);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static Toolkit find_ascend_toolkit() {
|
|
156
|
+
// Find Ascend home
|
|
157
|
+
std::filesystem::path home_path = get_env<std::string>("ASCEND_HOME_PATH");
|
|
158
|
+
if (home_path.empty())
|
|
159
|
+
home_path = get_env<std::string>("ASCEND_TOOLKIT_HOME");
|
|
160
|
+
if (home_path.empty() and std::filesystem::exists("/usr/local/Ascend/ascend-toolkit/latest"))
|
|
161
|
+
home_path = "/usr/local/Ascend/ascend-toolkit/latest";
|
|
162
|
+
if (home_path.empty() and std::filesystem::exists("/usr/local/Ascend/cann"))
|
|
163
|
+
home_path = "/usr/local/Ascend/cann";
|
|
164
|
+
|
|
165
|
+
DJ_HOST_ASSERT(not home_path.empty() and std::filesystem::is_directory(home_path),
|
|
166
|
+
"Ascend toolkit home was not found");
|
|
167
|
+
home_path = std::filesystem::absolute(home_path).lexically_normal();
|
|
168
|
+
|
|
169
|
+
const auto bisheng = home_path / "bin/bisheng";
|
|
170
|
+
const auto ld_lld = home_path / "bin/ld.lld";
|
|
171
|
+
DJ_HOST_ASSERT(is_executable(bisheng), "Bisheng compiler is not executable: {}", bisheng.string());
|
|
172
|
+
DJ_HOST_ASSERT(is_executable(ld_lld), "Ascend linker is not executable: {}", ld_lld.string());
|
|
173
|
+
|
|
174
|
+
const auto asc_devkit_include = home_path / "aarch64-linux/asc/include/adv_api";
|
|
175
|
+
DJ_HOST_ASSERT(std::filesystem::is_directory(asc_devkit_include),
|
|
176
|
+
"Ascend adv_api include directory was not found: {}", asc_devkit_include.string());
|
|
177
|
+
return {
|
|
178
|
+
.bisheng = bisheng,
|
|
179
|
+
.ld_lld = ld_lld,
|
|
180
|
+
.asc_devkit_include = asc_devkit_include,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
} // namespace deep_jit
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <cstdint>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
#include <deep_jit/backend/ascend/driver.hpp>
|
|
7
|
+
#include <deep_jit/utils/exception.hpp>
|
|
8
|
+
|
|
9
|
+
namespace deep_jit::ascend {
|
|
10
|
+
|
|
11
|
+
struct DeviceProperties {
|
|
12
|
+
std::string soc_name;
|
|
13
|
+
int64_t num_aicpu_cores = 0;
|
|
14
|
+
int64_t num_aicore_cores = 0;
|
|
15
|
+
int64_t num_cube_cores = 0;
|
|
16
|
+
int64_t num_vec_cores = 0;
|
|
17
|
+
int64_t num_lanes_per_warp = 0;
|
|
18
|
+
int64_t num_max_threads_per_vec_core = 0;
|
|
19
|
+
int64_t num_ubuf_bytes_per_vec_core = 0;
|
|
20
|
+
int64_t num_total_global_mem_bytes = 0;
|
|
21
|
+
int64_t num_l2_cache_bytes = 0;
|
|
22
|
+
int64_t npu_arch = 0;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
class Device {
|
|
26
|
+
DeviceProperties prop{};
|
|
27
|
+
bool initialized = false;
|
|
28
|
+
|
|
29
|
+
public:
|
|
30
|
+
const DeviceProperties& get_prop() {
|
|
31
|
+
if (not initialized) {
|
|
32
|
+
int device_index = 0;
|
|
33
|
+
DJ_ACL_CHECK(driver::lazy_aclrtGetDevice(&device_index));
|
|
34
|
+
const char* soc_name = driver::lazy_aclrtGetSocName();
|
|
35
|
+
DJ_HOST_ASSERT(soc_name != nullptr, "aclrtGetSocName returned null");
|
|
36
|
+
prop.soc_name = soc_name;
|
|
37
|
+
|
|
38
|
+
#define DJ_ASCEND_GET_PROP(name, attribute) \
|
|
39
|
+
DJ_ACL_CHECK(driver::lazy_aclrtGetDeviceInfo(device_index, attribute, &prop.name))
|
|
40
|
+
DJ_ASCEND_GET_PROP(num_aicpu_cores, ACL_DEV_ATTR_AICPU_CORE_NUM);
|
|
41
|
+
DJ_ASCEND_GET_PROP(num_aicore_cores, ACL_DEV_ATTR_AICORE_CORE_NUM);
|
|
42
|
+
DJ_ASCEND_GET_PROP(num_cube_cores, ACL_DEV_ATTR_CUBE_CORE_NUM);
|
|
43
|
+
DJ_ASCEND_GET_PROP(num_vec_cores, ACL_DEV_ATTR_VECTOR_CORE_NUM);
|
|
44
|
+
DJ_ASCEND_GET_PROP(num_lanes_per_warp, ACL_DEV_ATTR_WARP_SIZE);
|
|
45
|
+
DJ_ASCEND_GET_PROP(num_max_threads_per_vec_core, ACL_DEV_ATTR_MAX_THREAD_PER_VECTOR_CORE);
|
|
46
|
+
DJ_ASCEND_GET_PROP(num_ubuf_bytes_per_vec_core, ACL_DEV_ATTR_UBUF_PER_VECTOR_CORE);
|
|
47
|
+
DJ_ASCEND_GET_PROP(num_total_global_mem_bytes, ACL_DEV_ATTR_TOTAL_GLOBAL_MEM_SIZE);
|
|
48
|
+
DJ_ASCEND_GET_PROP(num_l2_cache_bytes, ACL_DEV_ATTR_L2_CACHE_SIZE);
|
|
49
|
+
DJ_ASCEND_GET_PROP(npu_arch, ACL_DEV_ATTR_NPU_ARCH);
|
|
50
|
+
#undef DJ_ASCEND_GET_PROP
|
|
51
|
+
initialized = true;
|
|
52
|
+
}
|
|
53
|
+
return prop;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
int get_npu_arch() { return static_cast<int>(get_prop().npu_arch); }
|
|
57
|
+
|
|
58
|
+
int get_num_aicore_cores() { return static_cast<int>(get_prop().num_aicore_cores); }
|
|
59
|
+
|
|
60
|
+
int get_num_sms() { return get_num_aicore_cores(); }
|
|
61
|
+
|
|
62
|
+
int get_num_vec_cores() { return static_cast<int>(get_prop().num_vec_cores); }
|
|
63
|
+
|
|
64
|
+
int get_num_cube_cores() { return static_cast<int>(get_prop().num_cube_cores); }
|
|
65
|
+
|
|
66
|
+
int get_num_vec_cores_per_ai_core() {
|
|
67
|
+
const auto num_ai_cores = get_num_aicore_cores();
|
|
68
|
+
const auto num_vector_cores = get_num_vec_cores();
|
|
69
|
+
DJ_HOST_ASSERT(num_ai_cores > 0 and num_vector_cores % num_ai_cores == 0,
|
|
70
|
+
"Ascend vector core count must be divisible by AI core count");
|
|
71
|
+
return num_vector_cores / num_ai_cores;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
int64_t get_num_l2_cache_bytes() { return get_prop().num_l2_cache_bytes; }
|
|
75
|
+
|
|
76
|
+
int64_t get_num_ubuf_bytes_per_vec_core() { return get_prop().num_ubuf_bytes_per_vec_core; }
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
} // namespace deep_jit::ascend
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <acl/acl.h>
|
|
4
|
+
|
|
5
|
+
#include <deep_jit/utils/exception.hpp>
|
|
6
|
+
#include <deep_jit/utils/lazy.hpp>
|
|
7
|
+
|
|
8
|
+
namespace deep_jit::ascend::driver {
|
|
9
|
+
|
|
10
|
+
DJ_DECL_LAZY_DL_HANDLE(get_acl_handle, "libascendcl.so");
|
|
11
|
+
|
|
12
|
+
DJ_DECL_LAZY_DL_FUNCTION(get_acl_handle, aclGetRecentErrMsg);
|
|
13
|
+
DJ_DECL_LAZY_DL_FUNCTION(get_acl_handle, aclrtBinaryLoadFromFile);
|
|
14
|
+
DJ_DECL_LAZY_DL_FUNCTION(get_acl_handle, aclrtBinaryUnLoad);
|
|
15
|
+
DJ_DECL_LAZY_DL_FUNCTION(get_acl_handle, aclrtBinaryGetFunction);
|
|
16
|
+
DJ_DECL_LAZY_DL_FUNCTION(get_acl_handle, aclrtLaunchKernelWithHostArgs);
|
|
17
|
+
DJ_DECL_LAZY_DL_FUNCTION(get_acl_handle, aclrtGetDevice);
|
|
18
|
+
DJ_DECL_LAZY_DL_FUNCTION(get_acl_handle, aclrtGetSocName);
|
|
19
|
+
DJ_DECL_LAZY_DL_FUNCTION(get_acl_handle, aclrtGetDeviceInfo);
|
|
20
|
+
DJ_DECL_LAZY_DL_FUNCTION(get_acl_handle, aclrtSynchronizeDevice);
|
|
21
|
+
|
|
22
|
+
inline void check_acl(const aclError error, const char* expression) {
|
|
23
|
+
if (error == ACL_SUCCESS)
|
|
24
|
+
return;
|
|
25
|
+
|
|
26
|
+
const char* message = lazy_aclGetRecentErrMsg();
|
|
27
|
+
DJ_PANIC("{} failed with ACL error {}: {}",
|
|
28
|
+
expression,
|
|
29
|
+
static_cast<int>(error),
|
|
30
|
+
message == nullptr ? "unknown" : message);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#ifndef DJ_ACL_CHECK
|
|
34
|
+
#define DJ_ACL_CHECK(expr) ::deep_jit::ascend::driver::check_acl((expr), #expr)
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
} // namespace deep_jit::ascend::driver
|