mirror of https://github.com/Jittor/Jittor
Merge branch 'master' of https://github.com/Jittor/jittor into fix_tuner_bug
This commit is contained in:
commit
9a53d49d9b
18
README.cn.md
18
README.cn.md
|
@ -85,6 +85,8 @@ Jittor的环境要求如下:
|
|||
* C++编译器(g++ or clang)
|
||||
|
||||
|
||||
|
||||
|
||||
Jittor 一共提供三种方式安装: pip安装, 一键脚本安装 和 手动安装.
|
||||
|
||||
## Pip 安装
|
||||
|
@ -94,13 +96,13 @@ Jittor 一共提供三种方式安装: pip安装, 一键脚本安装 和 手动
|
|||
(如果无法访问github, 可以通过jittor主页下载):
|
||||
|
||||
```bash
|
||||
sudo apt install python-dev libomp-dev
|
||||
sudo pip install https://github.com/Jittor/jittor.git
|
||||
sudo apt install python3.7-dev libomp-dev
|
||||
sudo python3.7 -m pip install git+https://github.com/Jittor/jittor.git
|
||||
# if you cannot access github, please download code from our website:
|
||||
# wget https://cg.cs.tsinghua.edu.cn/jittor/assets/build/jittor.tgz
|
||||
# mkdir -p jittor && tar -xvf ./jittor.tgz -C jittor
|
||||
# sudo pip install ./jittor
|
||||
python3 -m jittor.test.test_example
|
||||
python3.7 -m jittor.test.test_example
|
||||
```
|
||||
|
||||
如果测试运行通过,恭喜你已经安装完成.
|
||||
|
@ -298,11 +300,11 @@ help(jt.ops)
|
|||
|
||||
|
||||
|
||||
[1]: notebooks/example.md "示例"
|
||||
[2]: notebooks/basics.md "基本概念"
|
||||
[3]: notebooks/meta_op.md "元算子"
|
||||
[4]: notebooks/custom_op.md "自定义算子"
|
||||
[5]: notebooks/profiler.md "性能分析器"
|
||||
[1]: notebook/example.src.md "示例"
|
||||
[2]: notebook/basics.src.md "基本概念"
|
||||
[3]: notebook/meta_op.src.md "元算子"
|
||||
[4]: notebook/custom_op.src.md "自定义算子"
|
||||
[5]: notebook/profiler.src.md "性能分析器"
|
||||
|
||||
|
||||
这些notebooks可以通过python3.7 -m jittor.notebook在您自己的计算机中运行。
|
||||
|
|
24
README.md
24
README.md
|
@ -80,6 +80,12 @@ Jittor is written in Python and C++. It requires a compiler for JIT compilation,
|
|||
|
||||
|
||||
|
||||
Jittor environment requirements:
|
||||
|
||||
* System: Ubuntu >= 16.04
|
||||
* Python version >= 3.7
|
||||
* C++ compiler(g++ or clang)
|
||||
|
||||
Jittor offers three ways to install: pip, script or manual.
|
||||
|
||||
|
||||
|
@ -88,13 +94,13 @@ Jittor offers three ways to install: pip, script or manual.
|
|||
|
||||
|
||||
```bash
|
||||
sudo apt install python-dev libomp-dev
|
||||
sudo pip install https://github.com/Jittor/jittor.git
|
||||
sudo apt install python3.7-dev libomp-dev
|
||||
sudo python3.7 -m pip install git+https://github.com/Jittor/jittor.git
|
||||
# if you cannot access github, please download code from our website:
|
||||
# wget https://cg.cs.tsinghua.edu.cn/jittor/assets/build/jittor.tgz
|
||||
# mkdir -p jittor && tar -xvf ./jittor.tgz -C jittor
|
||||
# sudo pip install ./jittor
|
||||
python3 -m jittor.test.test_example
|
||||
python3.7 -m jittor.test.test_example
|
||||
```
|
||||
|
||||
|
||||
|
@ -235,7 +241,7 @@ print(c.name())
|
|||
# Output: c
|
||||
```
|
||||
|
||||
### Operations
|
||||
###Operations
|
||||
|
||||
|
||||
Jittor'op is simular with numpy. Let's try some operations. We create Var `a` and `b` via operation `jt.float32`, and add them. Printing those variables shows they have the same shape and dtype.
|
||||
|
@ -289,11 +295,11 @@ If you want to know more about Jittor, please check out the notebooks below:
|
|||
|
||||
|
||||
|
||||
[1]: notebooks/example.md "example"
|
||||
[2]: notebooks/basics.md "basics"
|
||||
[3]: notebooks/meta_op.md "meta_op"
|
||||
[4]: notebooks/custom_op.md "custom_op"
|
||||
[5]: notebooks/profiler.md "profiler"
|
||||
[1]: notebook/example.src.md "example"
|
||||
[2]: notebook/basics.src.md "basics"
|
||||
[3]: notebook/meta_op.src.md "meta_op"
|
||||
[4]: notebook/custom_op.src.md "custom_op"
|
||||
[5]: notebook/profiler.src.md "profiler"
|
||||
|
||||
Those notebooks can be started in your own computer by `python3.7 -m jittor.notebook`
|
||||
|
||||
|
|
|
@ -108,6 +108,12 @@ Jittor的环境要求如下:
|
|||
* Python版本 >= 3.7
|
||||
* C++编译器(g++ or clang)
|
||||
|
||||
Jittor environment requirements:
|
||||
|
||||
* System: Ubuntu >= 16.04
|
||||
* Python version >= 3.7
|
||||
* C++ compiler(g++ or clang)
|
||||
|
||||
Jittor offers three ways to install: pip, script or manual.
|
||||
|
||||
Jittor 一共提供三种方式安装: pip安装, 一键脚本安装 和 手动安装.
|
||||
|
@ -120,13 +126,13 @@ Jittor 一共提供三种方式安装: pip安装, 一键脚本安装 和 手动
|
|||
(如果无法访问github, 可以通过jittor主页下载):
|
||||
|
||||
```bash
|
||||
sudo apt install python-dev libomp-dev
|
||||
sudo pip install https://github.com/Jittor/jittor.git
|
||||
sudo apt install python3.7-dev libomp-dev
|
||||
sudo python3.7 -m pip install git+https://github.com/Jittor/jittor.git
|
||||
# if you cannot access github, please download code from our website:
|
||||
# wget https://cg.cs.tsinghua.edu.cn/jittor/assets/build/jittor.tgz
|
||||
# mkdir -p jittor && tar -xvf ./jittor.tgz -C jittor
|
||||
# sudo pip install ./jittor
|
||||
python3 -m jittor.test.test_example
|
||||
python3.7 -m jittor.test.test_example
|
||||
```
|
||||
|
||||
如果测试运行通过,恭喜你已经安装完成.
|
||||
|
@ -364,16 +370,16 @@ If you want to know more about Jittor, please check out the notebooks below:
|
|||
|
||||
|
||||
|
||||
[1]: notebooks/example.md "example"
|
||||
[2]: notebooks/basics.md "basics"
|
||||
[3]: notebooks/meta_op.md "meta_op"
|
||||
[4]: notebooks/custom_op.md "custom_op"
|
||||
[5]: notebooks/profiler.md "profiler"
|
||||
[1]: notebooks/example.md "示例"
|
||||
[2]: notebooks/basics.md "基本概念"
|
||||
[3]: notebooks/meta_op.md "元算子"
|
||||
[4]: notebooks/custom_op.md "自定义算子"
|
||||
[5]: notebooks/profiler.md "性能分析器"
|
||||
[1]: notebook/example.src.md "example"
|
||||
[2]: notebook/basics.src.md "basics"
|
||||
[3]: notebook/meta_op.src.md "meta_op"
|
||||
[4]: notebook/custom_op.src.md "custom_op"
|
||||
[5]: notebook/profiler.src.md "profiler"
|
||||
[1]: notebook/example.src.md "示例"
|
||||
[2]: notebook/basics.src.md "基本概念"
|
||||
[3]: notebook/meta_op.src.md "元算子"
|
||||
[4]: notebook/custom_op.src.md "自定义算子"
|
||||
[5]: notebook/profiler.src.md "性能分析器"
|
||||
|
||||
Those notebooks can be started in your own computer by `python3.7 -m jittor.notebook`
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ optim = nn.SGD (model.parameters(), learning_rate)
|
|||
|
||||
for i,(x,y) in enumerate(get_data(n)):
|
||||
pred_y = model(x)
|
||||
loss = ((pred_y - y)**2)
|
||||
loss = jt.sqr(pred_y - y)
|
||||
loss_mean = loss.mean()
|
||||
optim.step (loss_mean)
|
||||
print(f"step {i}, loss = {loss_mean.data.sum()}")
|
||||
|
|
|
@ -102,7 +102,7 @@ def conv(x, w):
|
|||
])
|
||||
ww = w.broadcast_var(xx)
|
||||
yy = xx*ww
|
||||
y = yy.sum([3,4,5]) # Kh, Kw, Kc
|
||||
y = yy.sum([3,4,5]) # Kh, Kw, c
|
||||
return y
|
||||
|
||||
# Let's disable tuner. This will cause jittor not to use mkl for convolution
|
||||
|
@ -150,7 +150,7 @@ xx = x.reindex([N,H-Kh+1,W-Kw+1,Kh,Kw,C,Kc], [
|
|||
])
|
||||
ww = w.broadcast_var(xx)
|
||||
yy = xx*ww
|
||||
y = yy.sum([3,4,5]) # Kh, Kw, Kc
|
||||
y = yy.sum([3,4,5]) # Kh, Kw, C
|
||||
```
|
||||
|
||||
**After expansion:**
|
||||
|
@ -159,7 +159,7 @@ y = yy.sum([3,4,5]) # Kh, Kw, Kc
|
|||
|
||||
```
|
||||
py
|
||||
shape = [N,H+Kh-1,W+Kw-1,Kh,Kw,C,Kc]
|
||||
shape = [N,H-Kh+1,W-Kw+1,Kh,Kw,C,Kc]
|
||||
# expansion of x.reindex
|
||||
xx = np.zeros(shape, x.dtype)
|
||||
for i0 in range(shape[0]):
|
||||
|
@ -170,9 +170,9 @@ for i0 in range(shape[0]):
|
|||
for i5 in range(shape[5]):
|
||||
for i6 in range(shape[6]):
|
||||
if is_overflow(i0,i1,i2,i3,i4,i5,i6):
|
||||
y[i0,i1,...,in] = 0
|
||||
xx[i0,i1,...,in] = 0
|
||||
else:
|
||||
y[i0,i1,i2,i3,i4,i5,i6] = x[i0,i1+i3,i2+i4,i5]
|
||||
xx[i0,i1,i2,i3,i4,i5,i6] = x[i0,i1+i3,i2+i4,i5]
|
||||
|
||||
# expansion of w.broadcast_var(xx)
|
||||
ww = np.zeros(shape, x.dtype)
|
||||
|
@ -223,7 +223,7 @@ for i0 in range(shape[0]):
|
|||
for i5 in range(shape[5]):
|
||||
for i6 in range(shape[6]):
|
||||
if not is_overflow(i0,i1,i2,i3,i4,i5,i6):
|
||||
y[i0,i1,i2,i6] += x[i0,i1+i3,i2+i4,i5]
|
||||
y[i0,i1,i2,i6] += x[i0,i1+i3,i2+i4,i5] * w[i3,i4,i5,i6]
|
||||
```
|
||||
|
||||
This is the trick of meta-operator, It can fused multiple operator into a complicated operation, including many variation of convolution (e.g. group conv, seperate conv,...).
|
||||
|
@ -249,4 +249,8 @@ with open(report[1][1], 'r') as f:
|
|||
|
||||
Even faster than the previous implementation! From the output we can look at the function definition of func0. This is the main code of our convolution kernel, which is generated Just-in-time. Because the compiler knows the shapes of the kernel and more optimizations are used.
|
||||
|
||||
比之前的实现还要更快! 从输出中我们可以看一看`func0`的函数定义,这是我们卷积内核的主要代码,该内核代码是即时生成的。因为编译器知道内核的形状,所以使用了更多的优化方法。
|
||||
比之前的实现还要更快! 从输出中我们可以看一看`func0`的函数定义,这是我们卷积内核的主要代码,该内核代码是即时生成的。因为编译器知道内核的形状,所以使用了更多的优化方法。
|
||||
|
||||
在这个教程中,Jittor简单演示了元算子的使用,并不是正真的性能测试,所以使用了比较小的数据规模进行测试,如果需要性能测试,请打开`jt.flags.enable_tuner = 1`,会启动使用专门的硬件库加速。
|
||||
|
||||
In this tutorial, Jittor simply demonstrated the use of meta-operators, which is not a performance test. If you need a performance test, `jt.flags.enable_tuner = 1` will try to use the dedicated hardware library.
|
||||
|
|
|
@ -691,7 +691,7 @@ def check_cuda():
|
|||
return
|
||||
global cc_flags, has_cuda, core_link_flags, cuda_dir, cuda_lib, cuda_include
|
||||
cuda_dir = os.path.dirname(get_full_path_of_executable(nvcc_path))
|
||||
assert cuda_dir.endswith("bin") and "cuda" in cuda_dir, f"Wrong cuda_dir: {cuda_dir}"
|
||||
assert cuda_dir.endswith("bin") and "cuda" in cuda_dir.lower(), f"Wrong cuda_dir: {cuda_dir}"
|
||||
cuda_include = os.path.abspath(os.path.join(cuda_dir, "..", "include"))
|
||||
cuda_lib = os.path.abspath(os.path.join(cuda_dir, "..", "lib64"))
|
||||
cuda_include2 = os.path.join(jittor_path, "extern","cuda","inc")
|
||||
|
|
|
@ -21,7 +21,7 @@ def conv(x, w):
|
|||
])
|
||||
ww = w.broadcast_var(xx)
|
||||
yy = xx*ww
|
||||
y = yy.sum([3,4,5]) # Kh, Kw, Kc
|
||||
y = yy.sum([3,4,5]) # Kh, Kw, C
|
||||
return y, yy
|
||||
|
||||
def conv_naive(x, w):
|
||||
|
@ -52,7 +52,7 @@ def conv_transpose(x, w):
|
|||
], 0, ['(i1-i3)%2', '(i2-i4)%2'])
|
||||
ww = w.broadcast_var(xx)
|
||||
yy = xx*ww
|
||||
y = yy.sum([3,4,5]) # Kh, Kw, Kc
|
||||
y = yy.sum([3,4,5]) # Kh, Kw, C
|
||||
return y, yy
|
||||
|
||||
def conv_transpose_naive(x, w):
|
||||
|
|
|
@ -134,9 +134,9 @@ def download(url, filename):
|
|||
if os.path.isfile(filename):
|
||||
if os.path.getsize(filename) > 100:
|
||||
return
|
||||
LOG.i("Downloading", url)
|
||||
LOG.v("Downloading", url)
|
||||
urllib.request.urlretrieve(url, filename)
|
||||
LOG.i("Download finished")
|
||||
LOG.v("Download finished")
|
||||
|
||||
def find_cache_path():
|
||||
from pathlib import Path
|
||||
|
|
|
@ -78,15 +78,15 @@ struct ReindexOp : Op {
|
|||
N,H,W,C = x.shape
|
||||
Kh, Kw, _C, Kc = w.shape
|
||||
assert C==_C
|
||||
xx = x.reindex([N,H+Kh-1,W+Kw-1,Kh,Kw,C,Kc], [
|
||||
xx = x.reindex([N,H-Kh+1,W-Kw+1,Kh,Kw,C,Kc], [
|
||||
'i0', # Nid
|
||||
'i1-i3', # Hid+Khid
|
||||
'i2-i4', # Wid+KWid
|
||||
'i1+i3', # Hid+Khid
|
||||
'i2+i4', # Wid+KWid
|
||||
'i5', # Cid
|
||||
])
|
||||
ww = w.broadcast_var(xx)
|
||||
yy = xx*ww
|
||||
y = yy.sum([3,4,5]) # Kh, Kw, Kc
|
||||
y = yy.sum([3,4,5]) # Kh, Kw, C
|
||||
return y, yy
|
||||
```
|
||||
*/
|
||||
|
@ -104,4 +104,4 @@ struct ReindexOp : Op {
|
|||
DECLARE_jit_run;
|
||||
};
|
||||
|
||||
} // jittor
|
||||
} // jittor
|
||||
|
|
Loading…
Reference in New Issue