Posts

Dissecting OpenCL code

Image
In my previous post , I got sample OpenCL matrix multiplication kernel to run inside Python on Windows. That was one of the first time I got to work on openCL. The code itself is pretty self explanatory for the most part, but it is interesting to see the comparisons with CUDA, and also how the kernel gets invoked though python. import pyopencl as cl import numpy as np import os os.environ['PYOPENCL_CTX']='0' (n, m, p) = (3, 4, 5) a = np.random.randn(n, m).astype(np.float32) b = np.random.randn(m, p).astype(np.float32) c = np.zeros((n*p), dtype=np.float32) context = cl.create_some_context() queue = cl.CommandQueue(context) mf = cl.mem_flags a_buf = cl.Buffer(context, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a) b_buf = cl.Buffer(context, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=b) c_buf = cl.Buffer(context, mf.WRITE_ONLY, c.nbytes) prg = cl.Program(context, """ __kernel void multiply(ushort n, ushort m, ushort p, __global float *a, __global fl...

Running pyopencl in Windows

Image
After my failed attempt at executing openCL code on my AMD APU mini PC within WSL, I'm now attempting to do that in Windows. I haven't coded in python on Windows before, so I had to look up on how I can create a virtual env, and activate it. It was fairly straighforward with the use of powershell, which allowed me to use some of the Linux commands familiar to me. After install pyopencl by running pip install pyopencl and then jumped into the python console import pyopencl from pyopencl.tools import get_test_platforms_and_devices get_test_platforms_and_devices() gave me a warning about not having siphash24 installed (which I installed later) but it was also showing the GPU as an opencl device [(<pyopencl.Platform 'AMD Accelerated Parallel Processing' at 0x7ff8f0e98000>, [<pyopencl.Device 'gfx902' on 'AMD Accelerated Parallel Processing' at 0x146c185c0b0>])] Getting back to the exercise at https://homepages.math.uic.edu/~jan/mcs...

Getting Started with pyOpenCL in WSL

Image
In the past, I experimented with GPU programming, using CUDA on Nvidia GPUs. Back then, the bandwidth of the PCIe interface between the CPU and the GPU was deemed to be one of it's Achilles heel. It was about the same time when AMD was putting out APUs post-ATI acquisition, but at that time, the company was just struggling compared to it's peer, Nvidia. Having highly capable and complex CPU cores with massively parallel  GPU cores share the same memory space and working together in a heterogeneous compute environment sounded like a dream. I recently had to look into buying a Windows PC for my wife and I found some nice used mini PCs with a  35 W AMD Ryzen 5 PRO 2400GE on ebay. I found them very interesting and decided to purchase one.  I'll attempt to use this GPU for general purpose compute and see how things go. I'll just install the necessary libraries, and run some sample code. This is also an opportunity for me to test this out in WSL and see if it works. I use...

Functional Ideology when using TypeScript

Angular Developer Victor Savkin writes about using functional programming paradigm when writing TypeScript. https://vsavkin.com/functional-typescript-316f0e003dc6#.ggpfzwlb6 His blog in general has good stuff around Angular 2/TypeScript https://vsavkin.com/

Web apps as desktop apps

A comparison of NW.js and Electron for packaging web applications as desktop applications. http://tangiblejs.com/posts/nw-js-and-electron-compared-2016-edition Also see:  https://github.com/MacGapProject  for Mac clients.

Installing nodejs

http://www.hostingadvice.com/how-to/install-nodejs-ubuntu-14-04/#node-version-manager For global install, in a sudo shell export NVM_DIR=/opt/nvm ( git clone https://github.com/creationix/nvm.git "$NVM_DIR" cd "$NVM_DIR" git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" origin` ) && . "$NVM_DIR/nvm.sh" vi ~/.bashrc And add the following code at the end. export NVM_DIR="/opt/nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm To use version 6.5 nvm use 6.5 Resources for node An Inside Look at the Architecture of NodeJS:  https://mcgill-csus.github.io/student_projects/Submission2.pdf Art of node: https://github.com/maxogden/art-of-node About node.js event loop https://nodesource.com/blog/understanding-the-nodejs-event-loop/ http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/ Learning resources for node: http://n...

Starting and using GT.M

To set UTF-8 and start gt.m. $ export gtm_chset="UTF-8" $ export LC_CTYPE="en_US.utf8" $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<path_to_gtm_installation_directory> $ export PATH=$PATH:<path_to_gtm_installation_directory> $ export localWorkingDir="/home/harish/mBackend/" $ source /opt/gtm/gtmprofile $ export gtmgbldir=$localWorkingDir/database $ export export gtmroutines="$localWorkingDir/o($localWorkingDir/r) /opt/gtm/libgtmutil" Launch with $ gtm If encryption is desired, set the gtm_passwd and gtm_dbkeys environment variables first and then run the gtm script