[ WeekendProjects ] Python and GPU

Wiken kali ini pengen nyobain gimana menggunakan python untuk gpu programming.. ga sampe terlalu detil, cuma instalasi dan running sample codenya doank.. yang penting link-link pentingnya sudah diamankan.. [emoji grinning face with smiling eyes]

1. PyCUDA = python + cuda

Download: pypi/pycuda
Instalasi: PyCuda/Installation
Dokumentasi: documen.tician.de/pycuda/

2. PyOpenCL = python + opencl

Download: pypi/pyopencl
Instalasi: PyOpenCL/Installation
Dokumentasi: documen.tician.de/pyopencl/

Untuk sementara itu dulu.. kalau ada kesempatan dan mood, kita lanjut lagi..  [emoji grinning face with smiling eyes]

MATLAB OpenCL Toolbox on Mac Lion


1. download toolbox source from this link and unzip it.
2. edit make.m

[sourcecode language=”bash”]
opencl_include_dir = ‘/System/Library/Frameworks/OpenCL.framework/Headers’;
mex(‘src/openclcmd.cpp’, ‘-Iinclude’, [‘-I’ opencl_include_dir]);

3. edit your ~/.matlab/R20XXa/mexopts.sh. Check lines after “maci64” line and modify CLIBS and CXXLIBS so they become:

[sourcecode language=”bash”]
CLIBS="$MLIBS -framework OpenCL"
CXXLIBS="$MLIBS -lstdc++ -framework OpenCL"

4. open MATLAB and go to the opencl-toolbox directory
5. run make

>> make

6. add this directory as MATLAB path

>> addpath /replace/with/the/directory/path/

errors in cuda 4.0

I’m just trying the cuda 4.0 on my macbook. And, as usual, i’m too lazy to read the “what’s new” page or doc. Just go straight to test it until got stuck with the errors.. 😀

Here, I’ll list any kind of errors i experienced with, and hopefully it’ll come along with solution.. 😛

First, i’m trying to compile an old simple code. This code was fine using cuda 3.2, but when I compile it using cuda 4.0, this kind of error comes out..

cudaLK.o:1203:53: warning: null character(s) ignored
cudaLK.o:1203:101: warning: null character(s) ignored
cudaLK.o:1203:112: warning: null character(s) preserved in literal
cudaLK.o:1203:112: warning: missing terminating ' character
cudaLK.o(1): error: unrecognized token

whoaa…… this forced me to read the programming guide, again..

Finally, when my eyes went to nvcc section, I got the clue… It looks like nvidia change the format of nvcc command.. In earlier version, simple nvcc command was

nvcc -c <cudacodefile>.cu -o <cudacodefile>.o

But for cuda 4.0, you don’t need to define the object file. nvcc will automatically define the object file based on the .cu file name. So, it should be simply..

nvcc -c <cudacodefile>.cu

to be continued later..

get EAGLview screenshot with transparency in landscape mode

this is NOT mine actually. the original source can be found at the end of this post. i post here just for helping people who may need it. so they don’t need to spend whole day for “googling” this like i did. 😀

the key to get the transparency is this line:

[code language=”cpp”]
CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedLast;

now, this is the complete method. NOTE: this is for landscape mode (480 x 320), if you want in portrait, simply modify the size.

[code language=”cpp” wraplines=”false”]
– (UIImage*) getGLScreenshot {
NSInteger myDataLength = 480 * 320 * 4;

// allocate array and read pixels into it.
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, 480, 320, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

// gl renders "upside down" so swap top to bottom into new array.
// there’s gotta be a better way, but this works.
GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
for(int y = 0; y <320; y++)
for(int x = 0; x < 480* 4; x++)
buffer2[(319 – y) * 480 * 4 + x] = buffer[y * 4 * 480 + x];

// make data provider with data.
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL,
buffer2, myDataLength, NULL);

// prep the ingredients
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * 480;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();

/***************** to handle the transparency/alpha ******************/
CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedLast;
//CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;

CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;

// make the cgimage
CGImageRef imageRef = CGImageCreate(480, 320, bitsPerComponent,
bitsPerPixel, bytesPerRow, colorSpaceRef,
bitmapInfo, provider, NULL, NO, renderingIntent);

// then make the uiimage from that
UIImage *myImage = [UIImage imageWithCGImage:imageRef];
return myImage;


Source: www.iphonedevsdk.com

shiva3d causes memory leaks on iphone

if you are working with shiva3d game engine on iphone, you may notice two memory leaks once you convert the runtime package (.stk file) to xcode project using shiva authoring tools.

the memory leaks are
1. related to AudioToolbox framework
2. related to NSString

for the first one, i have no idea how to resolve it, since it was related to one of ios frameworks, and even google didn’t know :D.

and for the second, it seems the authoring tools forgot to release a dynamic NSString variable. see the image below. red rectangle is the suspect variable that you could find in initWithCoder method of S3DEngine_EAGLView class (blue rectangles). to resolve this, simply release the variable as shown in green rectangle.

click for bigger image

import existing C++ code and its Makefile in Eclipse (Linux)

Cuma catatan doank biar gampang nyari kalo bsok lupa.. 😀 kbetulan lagi pengen nyobain ngutak-ngatik source code punya orang.. kbetulan jg lagi pengen ngrasain make Eclipse di Linux..

1. Create a new project, File > New > C++ Project.

2. C++ Project window will appear.

a. Give the project name same as the existing C++ code’s folder.

b. in Project Type column, select Makefile project > Empty project.

c. select the compiler type in the Toolchain column.

d. click Next and then Read More …