jittor在Ubuntu20.04.1中运行custom_op例程出现bug
问题描述:
我在windows下运行这段程序没有问题,转到Ubuntu中却报了错,docker版本和Jittor镜像都是完全一致的。不明白具体是什么原因导致的。
docker版本 20.10.7
程序:
import jittor as jt
header ="""
#pragma once
#include "op.h"
namespace jittor {
struct CustomOp : Op {
Var* output;
CustomOp(NanoVector shape, NanoString dtype=ns_float);
const char* name() const override { return "custom"; }
DECLARE_jit_run;
};
} // jittor
"""
src = """
#include "var.h"
#include "custom_op.h"
namespace jittor {
#ifndef JIT
CustomOp::CustomOp(NanoVector shape, NanoString dtype) {
flags.set(NodeFlags::_cuda, 1);
flags.set(NodeFlags::_cpu, 1);
output = create_output(shape, dtype);
}
void CustomOp::jit_prepare() {
add_jit_define("T", output->dtype());
}
#else // JIT
#ifdef JIT_cpu
void CustomOp::jit_run() {
index_t num = output->num;
auto* __restrict__ x = output->ptr<T>();
for (index_t i=0; i<num; i++)
x[i] = (T)i;
}
#else
// JIT_cuda
__global__ void kernel(index_t n, T *x) {
int index = blockIdx.x * blockDim.x + threadIdx.x;
int stride = blockDim.x * gridDim.x;
for (int i = index; i < n; i += stride)
x[i] = (T)-i;
}
void CustomOp::jit_run() {
index_t num = output->num;
auto* __restrict__ x = output->ptr<T>();
int blockSize = 256;
int numBlocks = (num + blockSize - 1) / blockSize;
kernel<<<numBlocks, blockSize>>>(num, x);
}
#endif // JIT_cpu
#endif // JIT
} // jittor
"""
my_op = jt.compile_custom_op(header, src, "custom", warp=False)
报错信息:
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/lib/python3.7/multiprocessing/pool.py", line 121, in worker
result = (True, func(*args, **kwds))
File "/usr/local/lib/python3.7/dist-packages/jittor_utils/__init__.py", line 146, in do_compile
return cc.cache_compile(cmd, cache_path, jittor_path)
RuntimeError: [f 0716 00:51:51.026669 96 log.cc:329] Check failed ret(256) == 0(0) Run cmd failed: cd /root/.cache/jittor/default/g++ && /usr/bin/g++ /root/.cache/jittor/default/g++/custom_ops/gen_ops_custom.cc -Wall -Werror -Wno-unknown-pragmas -std=c++14 -fPIC -march=native -fdiagnostics-color=always -I/usr/local/lib/python3.7/dist-packages/jittor/src -I/usr/include/python3.7m -I/usr/local/lib/python3.7/dist-packages/pybind11/include -I/root/.cache/jittor/default/g++ -O2 -I'/root/.cache/jittor/default/g++/custom_ops' -c -o /root/.cache/jittor/default/g++/obj_files/gen_ops_custom.cc.o
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
<ipython-input-1-d2b4a46fbb07> in <module>
64 """
65
---> 66 my_op = jt.compile_custom_op(header, src, "custom", warp=False)
/usr/local/lib/python3.7/dist-packages/jittor/lock.py in inner(*args, **kw)
30 def inner(*args, **kw):
31 with self:
---> 32 ret = func(*args, **kw)
33 return ret
34 return inner
/usr/local/lib/python3.7/dist-packages/jittor/compiler.py in compile_custom_op(header, source, op_name, warp)
584 with open(ccname, 'w') as f:
585 f.write(source)
--> 586 m = compile_custom_ops([hname, ccname])
587 return getattr(m, op_name)
588
/usr/local/lib/python3.7/dist-packages/jittor/lock.py in inner(*args, **kw)
30 def inner(*args, **kw):
31 with self:
---> 32 ret = func(*args, **kw)
33 return ret
34 return inner
/usr/local/lib/python3.7/dist-packages/jittor/compiler.py in compile_custom_ops(filenames, extra_flags, return_module, dlopen_flags, gen_name_)
673 LOG.vvv(f"Build custum ops lib:{gen_lib}")
674 LOG.vvvv(f"Build sources:{builds}")
--> 675 compile(cc_path, extra_flags+cc_flags+opt_flags+includes, builds, gen_lib)
676
677 # add python path and import
/usr/local/lib/python3.7/dist-packages/jittor/compiler.py in compile(compiler, flags, inputs, output, combind_build)
88 cmd = cmd.replace("-Ofast", "-O2")
89 cmds.append(cmd)
---> 90 jit_utils.run_cmds(cmds, cache_path, jittor_path, "Compiling "+base_output)
91 cmd = f"{compiler} {' '.join(obj_files)} {flags} {lto_flags} {link} -o {output}"
92 return do_compile(cmd)
/usr/local/lib/python3.7/dist-packages/jittor_utils/__init__.py in run_cmds(cmds, cache_path, jittor_path, msg)
176 n = len(cmds)
177 dp = DelayProgress(msg, n)
--> 178 for i,_ in enumerate(p.imap_unordered(do_compile, cmds)):
179 dp.update(i)
180 finally:
/usr/lib/python3.7/multiprocessing/pool.py in next(self, timeout)
746 if success:
747 return value
--> 748 raise value
749
750 __next__ = next # XXX
答
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答
本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。
因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。