Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGBUS (Misaligned Address Error) #571

Closed
NAThompson opened this issue May 22, 2024 · 1 comment
Closed

SIGBUS (Misaligned Address Error) #571

NAThompson opened this issue May 22, 2024 · 1 comment

Comments

@NAThompson
Copy link
Contributor

To reproduce:

$ python3
Python 3.11.9
$ uname -a
Darwin  23.4.0 Darwin Kernel Version 23.4.0: ; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020 arm64
$ ./rmtc_issue.py
fish: Job 1, './rmtc_issue.py' terminated by signal SIGBUS (Misaligned address error)

Code:

#!/usr/bin/env python3
from math import pi as π
import random
import numpy as np
from smt.surrogate_models import RMTB, RMTC
import matplotlib.pyplot as plt
import num_dual


dimension = 4
def generate_sine_surface_data(samples=10):
    training_points = np.full(shape=(samples, dimension), fill_value=np.nan)
    training_values = np.full(shape=samples, fill_value=np.nan)

    for i in range(samples):
        x = np.random.uniform(-1, 1, dimension)
        training_points[i, :] = x
        v = 1
        for j in range(dimension):
            v *= np.sin(π*x[j])
        training_values[i] = v
    return training_points, training_values


def rmtc_surrogate_model(training_points, training_values):
    limits = np.full(shape=(dimension, 2), fill_value=np.nan)
    for i in range(dimension):
        limits[i, 0] = -1
        limits[i, 1] = 1

    model = RMTC(
        xlimits=limits,
        num_elements=20,
        energy_weight=1e-15,
        regularization_weight=0.0,
        print_global=False,
    )
    model.set_training_values(training_points, training_values)
    model.train()
    return model


if __name__ == "__main__":
    training_points, training_values = generate_sine_surface_data()
    rmtc = rmtc_surrogate_model(training_points, training_values)
@NAThompson
Copy link
Contributor Author

NAThompson commented May 23, 2024

I have managed to get this pared down a bit further. First I apply the following diff:

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
modified: setup.py
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
@ setup.py:52 @ SMT 2.0 adds the capability to handle mixed-variable surrogate models \
and hierarchical variables.
"""

extra_compile_args = []
extra_compile_args = ['-fsanitize=address', '-fsanitize=undefined', '-g']
if not sys.platform.startswith("win"):
    extra_compile_args.append("-std=c++11")
smt/src/rmts/rmtc.cpp:172:13: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior smt/src/rmts/rmtc.cpp:172:13 in
AddressSanitizer:DEADLYSIGNAL
=================================================================
==4233==ERROR: AddressSanitizer: BUS on unknown address (pc 0x0001586fdc6c bp 0x00016bac5530 sp 0x00016bac52b0 T0)
==4233==The signal is caused by a READ memory access.
==4233==Hint: this fault was caused by a dereference of a high value address (see register values below).  Disassemble the provided pc to learn which register was used.
   #0 0x1586fdc6c in RMTC::compute_full_from_block(double*, double*, int*, int*)+0x600 (rmtsclib.cpython-39d-darwin.so:arm64+0x15c6c)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: BUS (rmtsclib.cpython-39d-darwin.so:arm64+0x15c6c) in RMTC::compute_full_from_block(double*, double*, int*, int*)+0x600
==4233==ABORTING
fish: Job 1, './rmtc_issue.py' terminated by signal SIGABRT (Abort)

Testing the natural fix int -> long now.

NAThompson added a commit to NAThompson/smt that referenced this issue May 23, 2024
In Issue SMTorg#571, I encountered a bus error.
Using AddressSanitizer, I traced the error to a negative memory index
caused by a 32 bit signed integer overflowing the bounds and requesting
memory from a negative index.

Swap out `int` for `long` so that more total memory can be addressed and
allow larger problem sizes.
relf pushed a commit that referenced this issue May 24, 2024
In Issue #571, I encountered a bus error.
Using AddressSanitizer, I traced the error to a negative memory index
caused by a 32 bit signed integer overflowing the bounds and requesting
memory from a negative index.

Swap out `int` for `long` so that more total memory can be addressed and
allow larger problem sizes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant