Accelerating a PyODE simulation with Bullet+Cuda or OpenCL

aws357
Posts: 9
Joined: Tue Jul 03, 2007 8:20 am

Accelerating a PyODE simulation with Bullet+Cuda or OpenCL

Post by aws357 »

I have a simulation with ~3000 capsules organized in 16 chains contained in a sphere.

It uses PyODE and I am quite happy with the results I have so far. Except that it's really really slow now. It was still reasonably fast for a 1000 capsule but with the increased number of object... meh.

I was thinking if it was possible to use recent advances in Bullet and Cuda OR OpenCL to speed up the simulation, without having to recode everything in a language I am not too familiar with (I love C++, but C++ does not love me...). in fact, I am mostly interested with the collision part of Bullet.

I heard many thing about a fabled Python Bullet, but I am under the impression it is in limbo for now (if it exists, I would love to try it).

I could use the Bullet that is in Blender (using blender python) but I don't know if it support GPU acceleration (I am under the impression that the answer is no...)

And the less fun, but most realistic one would be to use SWIG to wrap just the parts of Bullet that are involved in collision detection (btCudaBroadphase?) so I can call it in my python script instead of using the collision detection from ODE/PyODE...

What do you people think?
sipickles
Posts: 44
Joined: Thu Aug 07, 2008 6:57 am

Re: Accelerating a PyODE simulation with Bullet+Cuda or OpenCL

Post by sipickles »

I am doing it the hard way.

I am wrapping Bullet in boost.python. It works pretty well so far, well it did until I just broke my app (nothing to do with bullet I am sure! ;)

I have a whole c++ class which performs the bullet work. My python code simply queries it from time to time.

Extract from boost.python code:

Code: Select all

BOOST_PYTHON_MODULE(hybridZone)
{
    using namespace boost::python;

    class_<BulletSector>("BulletSector")
        .def("Init", &BulletSector::Init)
        .def("Update", &BulletSector::Update)
        .def("AddHeightmap", &BulletSector::AddHeightmap)
        .def("AddModel", &BulletSector::AddModel)
        .def("RemoveModel", &BulletSector::RemoveModel)
        .def("GetElevation", &BulletSector::GetElevation)
	;

    class_<BulletModel>("BulletModel")
        .def("Init", &BulletModel::Init)
        .def("AddPart", &BulletModel::AddPart)
        .def("MakeBody", &BulletModel::MakeBody)
        .def("GetPositionX", &BulletModel::GetPositionX)
        .def("GetPositionY", &BulletModel::GetPositionY)
        .def("GetPositionZ", &BulletModel::GetPositionZ)
        .def("GetRotationX", &BulletModel::GetRotationX)
        .def("GetRotationY", &BulletModel::GetRotationY)
        .def("GetRotationZ", &BulletModel::GetRotationZ)
        .def("GetRotationW", &BulletModel::GetRotationW)
        .def("GetLinearVelocityX", &BulletModel::GetLinearVelocityX)
        .def("GetLinearVelocityY", &BulletModel::GetLinearVelocityY)
        .def("GetLinearVelocityZ", &BulletModel::GetLinearVelocityZ)
        .def("GetAngularVelocityX", &BulletModel::GetAngularVelocityX)
        .def("GetAngularVelocityY", &BulletModel::GetAngularVelocityY)
        .def("GetAngularVelocityZ", &BulletModel::GetAngularVelocityZ)
        .def("SetStartingPositionRotation", &BulletModel::SetStartingPositionRotation)
        .def("GetActivationState", &BulletModel::GetActivationState)
        .def("Pitch", &BulletModel::Pitch)
        .def("Roll", &BulletModel::Roll)
        .def("Yaw", &BulletModel::Yaw)
        .def("PitchRollYaw", &BulletModel::PitchRollYaw)
        .def("Lift", &BulletModel::Lift)
        ;
		
    class_<btVector3>("BtVector3", init<float, float, float>())
        ;

    class_<btBoxShape>("BtBoxShape", init<const btVector3 &>())
        ;
}
User avatar
TomorrowPlusX
Posts: 14
Joined: Wed Apr 16, 2008 11:45 am

Re: Accelerating a PyODE simulation with Bullet+Cuda or OpenCL

Post by TomorrowPlusX »

When you're done with that Boost.Python binding, it will probablycompile to more object code than Bullet itself :lol:

(I say this from some experience -- my Boost.Python bindings are larger than the rest of my game engine all together)
aws357
Posts: 9
Joined: Tue Jul 03, 2007 8:20 am

Re: Accelerating a PyODE simulation with Bullet+Cuda or OpenCL

Post by aws357 »

:shock: That's... not exactly... helping...

I'm familiar with python and C/C++ scare the shit out of me...

All I can possibly hope is to call CUDA/Bullet collision detection when I need... except for collision, other part of the simulation are really fast.

:| But I'm lost regarding what to wrap, and hoping that it is wrappable somehow...

(my current simulation runs for 15 days, if I could even cut that in half it would be worth the headache :cry: )