Skip to content

Commit

Permalink
Disable avx2 python extension due to colab crash
Browse files Browse the repository at this point in the history
Related issue: #432
  • Loading branch information
Strilanc committed Nov 19, 2022
1 parent ee7dc78 commit 465d1bf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
9 changes: 5 additions & 4 deletions glue/python/src/stim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import stim._detect_machine_architecture as _tmp

_tmp = _tmp._UNSTABLE_detect_march()
if _tmp == 'avx2':
from stim._stim_avx2 import *
from stim._stim_avx2 import _UNSTABLE_raw_gate_data, _UNSTABLE_raw_format_data, __version__
elif _tmp == 'sse2':
# NOTE: avx2 disabled until https://github.com/quantumlib/Stim/issues/432 is fixed
# if _tmp == 'avx2':
# from stim._stim_avx2 import *
# from stim._stim_avx2 import _UNSTABLE_raw_gate_data, _UNSTABLE_raw_format_data, __version__
if _tmp == 'avx2' or _tmp == 'sse2':
from stim._stim_sse2 import *
from stim._stim_sse2 import _UNSTABLE_raw_gate_data, _UNSTABLE_raw_format_data, __version__
else:
Expand Down
26 changes: 14 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,20 @@
'-DSTIM_PYBIND11_MODULE_NAME=_stim_sse2',
],
)
stim_avx2 = Extension(
'stim._stim_avx2',
sources=RELEVANT_SOURCE_FILES,
include_dirs=[pybind11.get_include(), "src"],
language='c++',
extra_compile_args=[
*common_compile_args,
'-msse2',
'-mavx2',
'-DSTIM_PYBIND11_MODULE_NAME=_stim_avx2',
],
)

# NOTE: disabled until https://github.com/quantumlib/Stim/issues/432 is fixed
# stim_avx2 = Extension(
# 'stim._stim_avx2',
# sources=RELEVANT_SOURCE_FILES,
# include_dirs=[pybind11.get_include(), "src"],
# language='c++',
# extra_compile_args=[
# *common_compile_args,
# '-msse2',
# '-mavx2',
# '-DSTIM_PYBIND11_MODULE_NAME=_stim_avx2',
# ],
# )

with open('glue/python/README.md', encoding='UTF-8') as f:
long_description = f.read()
Expand Down
30 changes: 22 additions & 8 deletions src/stim/mem/monotonic_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,40 @@ struct MonotonicBuffer {
ensure_available(reserve);
}
~MonotonicBuffer() {
for (auto &v : old_areas) {
free(v.ptr_start);
std::vector<PointerRange<T>> to_delete_old = std::move(old_areas);
T *to_delete_cur = cur.ptr_start;

old_areas.clear();
cur.ptr_start = nullptr;
cur.ptr_end = nullptr;
tail.ptr_start = nullptr;
tail.ptr_end = nullptr;

for (const auto &old : to_delete_old) {
free(old.ptr_start);
}
if (cur.ptr_start) {
free(cur.ptr_start);
if (to_delete_cur != nullptr) {
free(to_delete_cur);
}
old_areas.clear();
cur.ptr_start = cur.ptr_end = tail.ptr_start = tail.ptr_end = nullptr;
}
MonotonicBuffer(MonotonicBuffer &&other) noexcept
: tail(other.tail), cur(other.cur), old_areas(std::move(other.old_areas)) {
other.cur.ptr_start = nullptr;
other.cur.ptr_end = nullptr;
other.tail.ptr_start = nullptr;
other.tail.ptr_end = nullptr;
other.old_areas.clear();
}
MonotonicBuffer(const MonotonicBuffer &other) = delete;
MonotonicBuffer &operator=(MonotonicBuffer &&other) noexcept {
(*this).~MonotonicBuffer();
new (this) MonotonicBuffer(std::move(other));
tail = other.tail;
cur = other.cur;
old_areas = std::move(other.old_areas);
other.cur.ptr_start = nullptr;
other.cur.ptr_end = nullptr;
other.tail.ptr_start = nullptr;
other.tail.ptr_end = nullptr;
other.old_areas.clear();
return *this;
}

Expand Down

0 comments on commit 465d1bf

Please sign in to comment.