Page 1 of 1

Disable NEON

PostPosted: Thu Oct 25, 2012 8:38 pm
by barcelonans
Is it possible to disable NEON instructions for IOS? I need to compare NEON and non-NEON performance. If anyone has benchmark or demo examples, that would be really great

Re: Disable NEON

PostPosted: Thu Oct 25, 2012 9:00 pm
by slembcke
With Objective-Chipmunk, [[ChipmunkSpace alloc] init] will return a ChipmunkHastySpace if the hasty space class is linked in your executable. The NEON solver really has no downsides like the threaded one does. If you want to disable that functionality, you either need to edit the [ChipmunkSpace -init] method or remove ChipmunkHastySpace.m from the library target. Either case is going to require a recompile of Chipmunk Pro. It's also possible to do it with linker flags probably... but that sounds more complicated than it's worth.

Using the regular C API, you have to explicitly create a cpSpace or a cpHastySpace.

Re: Disable NEON

PostPosted: Fri Oct 26, 2012 12:39 am
by barcelonans
Thanks. I have downloaded the ChipmunkPro-Trial6.1.1 4, but cannot see the ChipmunkHastySpace.m. Have I downloaded the wrong thing?

Re: Disable NEON

PostPosted: Fri Oct 26, 2012 8:58 am
by slembcke
Oh. The trial does not come with the source code. The Chipmunk Indie package doesn't have the NEON optimizations, but does have the Objective-Chipmunk binding. You could compare the performance of those two.

Re: Disable NEON

PostPosted: Sun Oct 28, 2012 7:28 pm
by barcelonans
I bought the Pro version, and changed the the ChipmunkSpace init to not ever return a hastyspace with:

- (id)init {
// Use a fast space instead if the class is available.
// However if you don't specify -ObjC as a linker flag the dynamic substitution won't work.
Class hastySpace = NSClassFromString(@"ChipmunkHastySpace");
return [self initWithSpace:cpSpaceNew()];

I recompiled the whole thing and moved the libChipmunkPro-Iphone.a into the iphone demo project, cleaned and recompiled. Running on an Ipad, I expected to see a deterioration in the smoothness or the demos or something, but regardless of the settings, Time Scale or Time Step or even changing some of the values in the demos such as the tick value in the grabberDemo.m, I don't see any difference in the visual performance between, what I think I have in NEON mode and non-NEON mode. Am I missing something?

Re: Disable NEON

PostPosted: Sun Oct 28, 2012 9:03 pm
by slembcke
There is a benchmark target in the Chipmunk Pro project. That's where the numbers on the Chipmunk Pro site came from. The Chipmunk Showcase app on the other hand isn't really meant to be a benchmark, although it is supposed to saturate the CPU as much as possible on most devices. Did you also change the showcase source to use a regular Chipmunk space? It explicitly creates a ChipmunkHastySpace to enable multiple threads. Check ShowcaseDemo.m in the init method.

At least on my iPad 2, there is a *huge* difference in performance on the Pyramid Topple/Pyramid Stack demos if you force NEON/threading off. The framerate drops to the point where the UI become unresponsive and you can barely interact with it.

Re: Disable NEON

PostPosted: Mon Oct 29, 2012 12:37 am
by barcelonans
I didn't change the ShowcaseDemo.m. It looks like the init method has:

_space = [[self.spaceClass alloc] init];

and with _space defined as:

ChipmunkHastySpace *_space;

I tried the collapsing pyramid demo, and it looks about the same in NEON and obviously I am doing something wrong still. Can you tell me how ShowcaseDemo.m should look....Thanks

Re: Disable NEON

PostPosted: Mon Oct 29, 2012 10:35 am
by slembcke
Replace the first few lines of the init method like so:
Code: Select all
//      _space = [[self.spaceClass alloc] init];
//      // On iOS and OS X, 0 threads will automatically select the number of threads to use.
//      _space.threads = 0;
//      NSLog(@"cpHastySpace solver running on %d threads.", _space.threads);
      // Call the private initWithSpace: method and pass it a regular space.
      _space = objc_msgSend([ChipmunkSpace alloc], @selector(initWithSpace:), cpSpaceNew());

On an iPad 2, it's the difference between 12 and 60fps on the Pyramid demos. Not to say that it makes the physics alone 4x faster, but it frees up a lot time for rendering and the user interface code to run.

Re: Disable NEON

PostPosted: Mon Oct 29, 2012 8:37 pm
by barcelonans
Thanks for all your help so far. I have made the changes you suggested, and was really hoping for a dramatic visual demonstration of NEON against non-NEON. Both modes appear visually the same even on all of the demos. The performance display I get matches your statistics, 14 FPS on the non-NEON and 60 FPS on the NEON. Any ideas on how I would demonstrate that visually other than the performance numbers.

Re: Disable NEON

PostPosted: Mon Oct 29, 2012 10:06 pm
by AndyKorth
14 FPS to 60 FPS should have a pretty good visual effect. It should look pretty choppy at 14 fps compared to 60 fps.

Other than that, the NEON optimizations were designed to run the simulation and give the same results as the slower non-neon code. If the results were different, one of them would be wrong ;)

One thing to consider is that you could add a lot more physics objects because of the NEON optimization, but chipmunk won't randomly add objects to make up for that difference.