Archive for the ‘Uncategorized’ Category.

You don’t exist, go away!

new@compy:~> ssh localhost -lroot
You don’t exist, go away!
new@compy:~>

A paradoxical existential critic of your solipsistic non-existence is probably not what you want to be greeted with when attempting to administrate your box. The error actually means the system can’t lookup your userid. Which means your usernumber say 500 can’t be resolved to your username say: cpugwash.

Possible causes are:

Your user has been deleted from the /etc/passwd file.
Your user has been deleted from another authentication system you use, like LDAP.
Your LDAP or other authentication server is not running.

In my case, LDAP had crashed and needed restarting.

Some random rambling on this topic here.

Simple OpenCL example

Adapted from here: http://developer.amd.com/GPU/ATISTREAMSDK/pages/TutorialOpenCL.aspx

But tidied up a little and made to work on MacOS. It creates a OpenCL executor “thing” and tells it to run a kernel which writes “Hello World” to a buffer, this gets sent back to the main C++ program.

#include “cl.hpp”
#include
#include

std::string prog(
“#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable\n” \
“__constant char hw[] = \”Hello World\”; \n” \
“__kernel void hello(__global char * out) {\n” \
” size_t tid = get_global_id(0); \n” \
” out[tid] = hw[tid]; \n” \
“}\n”);

int main(void) {
cl_int err;

// Get list of platforms (things that can execute OpenCL on this host), get a “context” on the first executor.
std::vector platformList;
cl::Platform::get(&platformList);
cl_context_properties cprops[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties)(platformList[0])(), 0};
cl::Context context( CL_DEVICE_TYPE_CPU, cprops, NULL, NULL, &err);

// Allocate 100 bytes of memory which we will use to communicate with the OpenCL context, executor, whatever.
size_t mem_size = 100;
char * outH = new char[mem_size];
cl::Buffer outCL( context, CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR, mem_size, outH, &err);

// Give the OpenCL program embedded in the string above to OpenCL.
cl::Program::Sources source(1, std::make_pair(prog.c_str(), prog.length()+1));

// Get devices used in this “context”
std::vector devices;
devices = context.getInfo();

// Compile program against device
cl::Program program(context, source);
err = program.build(devices,””);

// create a kernel object, tell it we are using the kernel called “hello”, give it an argument which is the memory we alloc’d above.
cl::Kernel kernel(program, “hello”, &err);
err = kernel.setArg(0, outCL);

// Queue the kernel up to run
cl::CommandQueue queue(context, devices[0], 0, &err);
cl::Event event;
err = queue.enqueueNDRangeKernel( kernel, cl::NullRange, cl::NDRange(mem_size), cl::NDRange(1, 1), NULL, &event);

// Use the event object above to block until processing has completed
event.wait();

// Read the results out of the shared memory area.
err = queue.enqueueReadBuffer( outCL, CL_TRUE, 0, mem_size, outH);

// Write to screen
std::cout << outH; } [/sourcecode] On MacOS compile it with: g++ ./simple.cpp -framework OpenCL -o simple You'll also need to C++ bindings for OpenCL which are available here: http://www.khronos.org/registry/cl/api/1.0/cl.hpp Tarball containing all this is HERE untar it and type make to build.

Beagleboard GPIO Input (driverless)

The following example C program configures the beagleboard expansion header pins as GPIO inputs. the pins are configured all pull up. It then reads from these pins and output “1” if pin 3 ONLY is shorted to ground.

The code bypasses the kernel completely by mapping the memory containing the GPIO configuration registers directly. It does this by mmaping /dev/mem, to access system memory. You need to use O_SYNC when you do this to tell mmap the memory is uncacheable. It’ll work /a bit/ without but you’ll get weird artifacts.

Once you have access to memory you need to configure the pins to be used as GPIO. Each pin on the OMAP3530 can have up to 6 functions, by default the expansion header pins are configured for use as MMC and I2C ports. The pinconf code reconfigures these as GPIO, an input bit also needs to be set here. Next there another GPIO configuration register, which also needs setting to 1 for input. After this you can read GPIO data from the GPIO input register for bank 5. You can’t configure all the pins on bank 5 as input on the beagleboard, a couple of them are used for the main MMC port.

Bypassing the kernel isn’t the best way to access GPIO from userland. It’s possibly useful though if you’re planning to migrate the code in to a driver.

#include
#include
#include
#include
#include
#include
#include
#include

int main() {

int fd = open(“/dev/mem”, O_RDWR | O_SYNC);

if (fd < 0) { printf("Could not open memory\n"); return 0; } // Pad configuration volatile ulong *pinconf; pinconf = (ulong*) mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x48000000); if (pinconf == MAP_FAILED) { printf("Pinconf Mapping failed\n"); close(fd); return 0; } // Configure Expansion header pins as input. pinconf[0x2158/4] = 0x011C011C; pinconf[0x215C/4] = 0x011C011C; pinconf[0x2160/4] = 0x011C011C; pinconf[0x2164/4] = 0x011C011C; pinconf[0x2168/4] = 0x011C011C; pinconf[0x216C/4] = 0x011C011C; pinconf[0x2170/4] = 0x011C011C; pinconf[0x2188/4] = 0x011C011C; close(fd); fd = open("/dev/mem", O_RDWR | O_SYNC); // GPIO Configuration: configure are input volatile ulong *gpio; gpio = (ulong*) mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x49050000); if (gpio == MAP_FAILED) { printf("Gpio Mapping failed\n"); close(fd); return 0; } // Configure all GPIO pins on bank 5 as input. gpio[0x6034/4] = 0xFFFFFFFF; // Prints 1 when pin 3 of the Expansion header is Grounded. int c=0; for(;;) { if(gpio[0x6038/4] == 201390076) printf("1\n"); // printf("gpio5: %d \n",gpio[0x6038/4]); } } [/sourcecode]

Installing Ruby and running a program

I’ve written my first post on a first, simple Ruby program. But I’ve not included notes there on installing and running Ruby programs. That’s because Ruby runs on a lot of different systems. And Ruby programs can be run in different ways.

You can find advice on installing Ruby here.

If you’re using a Mac your in luck as Ruby is already installed on Snow Leopard and Lion! You’ll need a text editor though. Try TextWrangler. When you save files save them as myprogram.rb. To run them open up a terminal and type:

ruby myprogram.rb

You’ll need to make sure you’re in the same directory you saved your Ruby program to. By default TextWranger saves files to Documents so you’ll need to type:

cd Documents
ruby myprogram.rb

I hope that gets you started if you’re using a Mac. There are lots of instructions on getting up and running on other platforms around.