Compare commits

...

2 Commits

Author SHA1 Message Date
huochenghai 482b761f50
qemu system mode (#1201)
* close non-equal split

* fix typeinfer of conv2d

* fix fold binary

* do not swap binary args

* update setup.py

* do not pre-preprocess onnx with external data

* imgnore .mono in git

* restore SwapBinaryArgs

* fix onnx test runner

---------

Co-authored-by: sunnycase <sunnycase@live.cn>
2024-05-07 12:21:07 +08:00
Curio Yang a2869fa0f8
Feature/add xsgetn for char array buffer (#1198)
* Load multiple characters at once

* Apply code-format changes

* fix build

---------

Co-authored-by: curioyang <curioyang@users.noreply.github.com>
2024-05-07 10:47:18 +08:00
7 changed files with 35 additions and 17 deletions

3
.gitignore vendored
View File

@ -307,3 +307,6 @@ cmake-build-*
*.ipynb_checkpoints*
# Auto generated files
# generated/
.mono/
.history/

View File

@ -54,7 +54,7 @@ class nncaseConan(ConanFile):
self.requires('rapidjson/1.1.x')
if self.options.python:
self.requires('pybind11/2.6.1')
self.requires('pybind11/2.12.0')
if not self.options.runtime:
self.requires('abseil/20220623.1')

View File

@ -83,8 +83,7 @@ class InstallCMakeLibs(install_lib):
os.walk(os.path.join(bin_dir, 'sharplibs')) for _lib in files if
os.path.isfile(os.path.join(root, _lib)) and
(os.path.splitext(_lib)[-1] in [".dll", ".so", ".dylib", ".json"] or
_lib.startswith("lib"))
and not _lib.endswith(".deps.json")]
_lib.startswith("lib"))]
for lib in sharp_libs:
shutil.move(lib, os.path.join(self.build_dir,
@ -204,7 +203,7 @@ class BuildCMakeExt(build_ext):
extdir += os.path.sep
bin_dir = os.path.abspath(os.path.join(self.build_temp, 'install'))
cmake_args = ['-G', 'Ninja', '-DDOTNET_INIT_FOR_CONFIG=ON']
cmake_args = ['-G', 'Ninja', '-DDOTNET_INIT_FOR_CONFIG=OFF']
if platform.system() == 'Windows':
cmake_args += ['-DCMAKE_C_COMPILER=clang-cl']
cmake_args += ['-DCMAKE_CXX_COMPILER=clang-cl']

View File

@ -24,21 +24,21 @@ class char_array_buffer : public std::streambuf {
: begin_(data.begin()), end_(data.end()), current_(data.data()) {}
private:
int_type underflow() {
int_type underflow() override {
if (current_ == end_)
return traits_type::eof();
return traits_type::to_int_type(*current_);
}
int_type uflow() {
int_type uflow() override {
if (current_ == end_)
return traits_type::eof();
return traits_type::to_int_type(*current_++);
}
int_type pbackfail(int_type ch) {
int_type pbackfail(int_type ch) override {
if (current_ == begin_ ||
(ch != traits_type::eof() && ch != current_[-1]))
return traits_type::eof();
@ -46,13 +46,14 @@ class char_array_buffer : public std::streambuf {
return traits_type::to_int_type(*--current_);
}
std::streamsize showmanyc() {
std::streamsize showmanyc() override {
assert(std::less_equal<const char *>()(current_, end_));
return end_ - current_;
}
std::streampos seekoff(std::streamoff off, std::ios_base::seekdir way,
[[maybe_unused]] std::ios_base::openmode which) {
std::streampos
seekoff(std::streamoff off, std::ios_base::seekdir way,
[[maybe_unused]] std::ios_base::openmode which) override {
if (way == std::ios_base::beg) {
current_ = begin_ + off;
} else if (way == std::ios_base::cur) {
@ -67,8 +68,9 @@ class char_array_buffer : public std::streambuf {
return current_ - begin_;
}
std::streampos seekpos(std::streampos sp,
[[maybe_unused]] std::ios_base::openmode which) {
std::streampos
seekpos(std::streampos sp,
[[maybe_unused]] std::ios_base::openmode which) override {
current_ = begin_ + sp;
if (current_ < begin_ || current_ > end_)
@ -77,6 +79,17 @@ class char_array_buffer : public std::streambuf {
return current_ - begin_;
}
std::streamsize xsgetn(char_type *s, std::streamsize count) override {
std::streamsize available =
static_cast<std::streamsize>(end_ - current_);
std::streamsize n = (count > available) ? available : count;
if (n > 0) {
traits_type::copy(s, current_, static_cast<size_t>(n));
current_ += n;
}
return n;
}
const char *const begin_;
const char *const end_;
const char *current_;

View File

@ -17,7 +17,7 @@ public static class DistributedUtility
var ndsbp = new List<SBP>();
for (int axis = 0; axis < tensorType.Shape.Rank; axis++)
{
if (tensorType.Shape[axis] is { IsFixed: true, Value: int s } && IsDivideBy(s, placement.Hierarchy[i]))
if (tensorType.Shape[axis] is { IsFixed: true, Value: int s } && IsDivideExactly(s, placement.Hierarchy[i]))
{
ndsbp.Add(SBP.S(axis));
}
@ -50,7 +50,7 @@ public static class DistributedUtility
candidateNdsbps[i].Add(SBP.B);
for (int axis = 0; axis < tensorType.Shape.Rank; axis++)
{
if (tensorType.Shape[axis] is { IsFixed: true, Value: int s } && IsDivideBy(s, placement.Hierarchy[i]) && !innerSplitedAxes.Contains(axis))
if (tensorType.Shape[axis] is { IsFixed: true, Value: int s } && IsDivideExactly(s, placement.Hierarchy[i]) && !innerSplitedAxes.Contains(axis))
{
candidateNdsbps[i].Add(SBP.S(axis));
}
@ -73,7 +73,7 @@ public static class DistributedUtility
}
var divisors = GetDivisors(new DistributedType(tensorType, new IRArray<SBP>(ndsbp.ToArray()), placement));
return divisors.Select((d, axis) => (d, axis)).All(p => p.d == 0 ? true : IsDivideBy(tensorType.Shape[p.axis].FixedValue, p.d));
return divisors.Select((d, axis) => (d, axis)).All(p => p.d == 0 ? true : IsDivideExactly(tensorType.Shape[p.axis].FixedValue, p.d));
}
public static IReadOnlyList<int> GetDivisors(DistributedType distributedType)

View File

@ -129,7 +129,7 @@ public class Conv2DEvaluator : IEvaluator<Conv2D>, ITypeInferencer<Conv2D>, ICos
return new InvalidType(string.Empty);
}
if (input.Placement != weights.Placement)
if (input.Placement != weights.Placement || input.Placement != bias.Placement)
{
return new InvalidType("placement not equal");
}

View File

@ -58,11 +58,13 @@ class OnnxTestRunner(TestRunner):
elif model_file.startswith('onnx-models'):
model_file = os.path.join(os.getenv('ONNX_MODELS_DIR'),
model_file[len('onnx-models/'):])
has_external_data = False
if self.case_dir != os.path.dirname(model_file):
new_file = os.path.join(self.case_dir, 'test.onnx')
shutil.copy(model_file, new_file)
for tensor in external_data_helper._get_all_tensors(onnx.load(model_file, load_external_data=False)):
if external_data_helper.uses_external_data(tensor):
has_external_data = True
info = external_data_helper.ExternalDataInfo(tensor)
file_location = external_data_helper._sanitize_path(info.location)
external_data_src_path = os.path.join(
@ -76,7 +78,8 @@ class OnnxTestRunner(TestRunner):
if not self.inputs:
self.parse_model(model_file)
model_file = self.do_preprocess(model_file)
if not has_external_data:
model_file = self.do_preprocess(model_file)
super().run(model_file)