Skip to content

Commit

Permalink
Adding support to not native x86 systems even when compiling Stim sou…
Browse files Browse the repository at this point in the history
…rce (e.g. Pymatching)
  • Loading branch information
mghibaudi committed Mar 26, 2024
1 parent bc638e3 commit f8a2df5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY out)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY out)

# Convert desired SIMD_WIDTH into machine architecture flags.
if(NOT(SIMD_WIDTH))
set(MACHINE_FLAG "-march=native")
elseif(SIMD_WIDTH EQUAL 256)
set(MACHINE_FLAG "-mavx2" "-msse2")
elseif(SIMD_WIDTH EQUAL 128)
set(MACHINE_FLAG "-mno-avx2" "-msse2")
elseif(SIMD_WIDTH EQUAL 64)
set(MACHINE_FLAG "-mno-avx2" "-mno-sse2")
if (CMAKE_SYSTEM_PROCESSOR MATCHES x86_64)
if(NOT(SIMD_WIDTH))
set(MACHINE_FLAG "-march=native")
elseif(SIMD_WIDTH EQUAL 256)
set(MACHINE_FLAG "-mavx2" "-msse2")
elseif(SIMD_WIDTH EQUAL 128)
set(MACHINE_FLAG "-mno-avx2" "-msse2")
elseif(SIMD_WIDTH EQUAL 64)
set(MACHINE_FLAG "-mno-avx2" "-mno-sse2")
endif()
else ()
set(MACHINE_FLAG "")
endif()

# make changes to file_lists trigger a reconfigure
Expand Down
22 changes: 13 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import platform

from setuptools import setup, Extension
import glob
Expand All @@ -27,7 +27,7 @@

__version__ = '1.14.dev0'

if sys.platform.startswith('win'):
if platform.system().startswith('Win'):
common_compile_args = [
'/std:c++20',
'/O2',
Expand Down Expand Up @@ -97,6 +97,16 @@
with open('glue/python/README.md', encoding='UTF-8') as f:
long_description = f.read()

def _get_extensions():
if platform.processor().startswith("x86_64"):
# NOTE: disabled until https://github.com/quantumlib/Stim/issues/432 is fixed
# stim_avx2,
return [stim_detect_machine_architecture, stim_polyfill,
# stim_avx2,
stim_sse2]
else:
return [stim_detect_machine_architecture, stim_polyfill]

setup(
name='stim',
version=__version__,
Expand All @@ -107,13 +117,7 @@
description='A fast library for analyzing with quantum stabilizer circuits.',
long_description=long_description,
long_description_content_type='text/markdown',
ext_modules=[
stim_detect_machine_architecture,
stim_polyfill,
stim_sse2,
# NOTE: disabled until https://github.com/quantumlib/Stim/issues/432 is fixed
# stim_avx2,
],
ext_modules=_get_extensions(),
python_requires='>=3.6.0',
packages=['stim'],
package_dir={'stim': 'glue/python/src/stim'},
Expand Down

0 comments on commit f8a2df5

Please sign in to comment.