FLAMEGPU/FLAMEGPU2

agent python bug

Closed this issue · 2 comments

Describe the bug
define fuction like this:

@pyflamegpu.device_function
def vec3Length(x: float, y: float, z: float) -> float :
return math.sqrt(x * x + y * y + z * z)

@pyflamegpu.device_function
def vec3Mult(x: float, y: float, z: float, multiplier: float):
x *= multiplier
y *= multiplier
z *= multiplier

@pyflamegpu.device_function
def vec3Div(x: float, y: float, z: float, divisor: float):
x /= divisor
y /= divisor
z /= divisor

@pyflamegpu.device_function
def clampPosition(x: float, y: float, z: float, MIN_POSITION: float, MAX_POSITION: float):
x = MIN_POSITION if (x < MIN_POSITION) else x
x = MAX_POSITION if (x > MAX_POSITION) else x

y = MIN_POSITION if (y < MIN_POSITION) else y
y = MAX_POSITION if (y > MAX_POSITION) else y

z = MIN_POSITION if (z < MIN_POSITION) else z
z = MAX_POSITION if (z > MAX_POSITION) else z

and output like this:

flamegpu/runtime/messaging/MessageSpatial3D/MessageSpatial3DDevice.cuh(535)[0,0,0][383,0,0]:
Location (-0.500016, -0.252015, -0.208996) exceeds environment bounds (-0.5, -0.5, -0.5):(0.5, 0.5, 0.5), this is unsupported for the wrapped iterator, MessageSpatial3D::In::wrap().

-0.500016 < -0.5 hence it exceeds the bounds.

You should either clamp or wrap that value so that is within the inclusive bounds [-0.5, 0.5].

Edit: Appears you are trying to clamp, this might be some (annoying) floating point nuance.

Passing the code you've provided via pyflamegpu.codegen.translate produces correct looking c++

How are you calling clampPosition(), it's possible that's where the -0.500016 is being introduced (e.g. if a double is being cast to float).

FLAMEGPU_DEVICE_FUNCTION float vec3Length(float x, float y, float z){
    return sqrt((((x * x) + (y * y)) + (z * z)));
}

FLAMEGPU_DEVICE_FUNCTION void vec3Mult(float x, float y, float z, float multiplier){
    x *= multiplier;
    y *= multiplier;
    z *= multiplier;
}

FLAMEGPU_DEVICE_FUNCTION void vec3Div(float x, float y, float z, float divisor){
    x /= divisor;
    y /= divisor;
    z /= divisor;
}

FLAMEGPU_DEVICE_FUNCTION void clampPosition(float x, float y, float z, float MIN_POSITION, float MAX_POSITION){
    x = x < MIN_POSITION ? MIN_POSITION : x;
    x = x > MAX_POSITION ? MAX_POSITION : x;
    y = y < MIN_POSITION ? MIN_POSITION : y;
    y = y > MAX_POSITION ? MAX_POSITION : y;
    z = z < MIN_POSITION ? MIN_POSITION : z;
    z = z > MAX_POSITION ? MAX_POSITION : z;
}