Customize syntax highlighting for CUDA in Kate/KDevelop
CUDA is a minimal extension of C/C++ to support programming on newer NVIDIA GPUs. It introduces dozens of new keywords that are frequently used in CUDA programs. Adding syntax highlighting in KDevelop (Kate) only requires several simple steps:
1. Get keywords from “usertype.dat” provided by any Windows version of CUDA SDK, this is a text file. It should be found under $(NVIDIA_CUDA_SDK)\doc\syntax_highlighting.
2. Under your Linux account, cd ~/.kde/share/apps/katepart/syntax/, there should be two xml files regarding C/C++, cpp.xml and c.xml. Make a copy of both and name them properly, e.g. cpp_cuda.xml & c_cuda.xml.
3. Perform a replace operation on each keyword in “usertype.dat” so they match the keyword format in target xml files, and then copy them into the keyword lists of target files.
4. Modify xml header, which includes language description, file extensions and other information. You probably want to add “*.cu” to the file extension list. Remember to distinguish them from the original C/C++ language tag. Save the xml files after you are done.
5. Open Kate/KDevelop, under Tools->Highlighting->Sources you should see two new entries below C++ and C, respectively.
Enjoy.
Add comment June 6, 2008
Starting a subprocess from Python
subprocess is a convenient way to fork a new process on Windows/Unix/etc. It obsoletes previous methods such as commands (which does not support Windows) and os.system()/os.popen*/os.spawn*
Here is an example:
import subprocess
cmd_lst = ['exec_file', 'arg1', 'arg2', ...]
subprocess.call(cmd_lst) #return the value returned by the callee
subprocess.check_call(cmd_lst) #return if the callee exits with 0, otherwise raise an error
Add comment May 5, 2008
Surface by Microsoft
Happened to run into the link http://www.microsoft.com/surface, this is a product that’s been announced for over a year. Very impressive.
This somewhat proves, again, that computer science is neither about computer nor science, it is math and art.
Add comment April 2, 2008
Cygwin group/passwd setting
In case anything goes wrong with user accounts, carry on the following steps:
mkpasswd -l -c > /etc/passwd
mkgroup -l -c > /etc/group
mkpasswd -d -u <username> /etc/passwd (optional)
mkgroup -d | grep <username> /etc/group (optional)
1 comment February 17, 2008
How to- Tunnel Traffic through Firewall and Remote Desktop
My department has rigid access rules, which prevail in today’s internet jungle. Sadly enough, connecting to one’s working environment is not as easy as it used to be. It took more than a breath of time and understanding to configure all the access methods I need. Though all stated here are trivial, I feel keeping a memo quite necessary, especially when all the department guidelines themselves are within the firewall.
Scenario
a) IP address space protected by a filewall
b) Access server sitting just on border of the firewall, only tunneling allowed
c) Well-known department servers inside the filewall
d) Office computer, with domain/username account and domain-affiliated NFS (OS: Windows XP SP2)
e) Home computer, OS: Windows Vista (yes, I know Linux will make remote access easier, but what about drivers of all the cool new hardware I paid big money for?)
Software on client side: OpenSSH (on Cygwin) or PuTTY or SSH Secure Shell, WinSCP
Goal 1: Set up tunnels through a border server
Edit the configuration file for OpenSSH (or do similar stuff to other clients), open the file ~/.ssh/config and put the following lines in:
host name_it_yourself
hostname hostname_domainname
user username
ForwardAgent yes
LocalForward custom_port1 hostname1:port1 #list as many as u wish
LocalForward custom_port2 hostname2:port2
IdentityFile ~/.ssh/key_for_host/id_dsa #where to store private key if pubkey is used
kick-start everything else with ssh name_it_yourself and leave it running in the background. From now on, all remote access appear as reaching for some local customized port. All the ugly things (almost all) are taken care of by the tunneling mechanism.
Goal 2: Connect to well know server inside firewall
Specify a portforwarding rule in 1, and then create a new profile (i.e. adding a new paragraph in OpenSSH config file) looking like this:
host name_it_yourself
hostname localhost # since we have already tunneled it
user username
ForwardX11 yes
port custom_port1
IdentityFile ~/.ssh/id_file
Login by running ssh name_it_yourself
Goal 3: SSH to office computer
A SSH server is required on the remote end, OpenSSH on Cygwin is one of the easiest way to do this. Set OpenSSH to service mode so that sshd.exe is lauched at booting.
On the client side, add another profile for office computer similar to 2. Remember to set up a tunnel in 1. With better control of the server end, public key authentication can be used to save password typing. Use ssh-keygen under Cygwin for a pair of keys:
ssh-keygen -f ~/.ssh/key_file -t rsa #specify where to put keys and which authentication protocol to use
Keep the private key safe and sound, probably protecting it by a password.
Distribute the pub key file on office computer by concatenate it to the SSH authorized key file (change path of the pub key accordingly):
cat ~/key_file.pub >> ~/.ssh/authorized_keys
Note: If you are using PuTTY for tunneling, remember that pub key pairs generated by PuTTY is not 100% compatible with OpenSSH. Minor modification required, or simply stick to ssh-keygen and import it in PuTTY.
Goal 4: FTP-like file access
WinSCP is a good candidate, supporting SCP and SFTP. Create a new profile in WinSCP, if pubkey is used, private key file should be loaded. WinSCP uses PuTTY style private key, and OpenSSH keys are alien to it. Therefore, a private key generated in a UNIX environment should be imported using PuTTYgen.exe and saved in PuTTY style (.ppk) before using.
Goal 5: Remote desktop to office computer
Add a tunnel to the remote RDP port by adding a line to profile in 1:
LocalForward local_port office_computer_domain:RDP_port
Make sure remote desktop is allowed on remote OS and the user is granted access. Run remote desktop on local machine and access localhost:local_port.
Note On Windows XP SP2, access to 127.0.0.1: is not allowed (loopback), use 127.0.0.2 instead. On Windows XP/2003, RDP listens on port 3389, while Windows Vista listens on 3390. Therefore, one cannot map these port as the local_port.
1 comment September 25, 2007
More LaTeX Templates
%preamble
\RequirePackage[config]{subfig}
%%%%%%%%%%%%%%%%%figure-Title%%%%%%%%%%%%%%%%
\begin{figure}[hbtp]
\centering
\subfloat{\includegraphics[width=.48\textwidth]{subfig-1}}
\subfloat{\includegraphics[width=.48\textwidth]{subfig-2}}
\caption{Foobar}
\label{fig:foobar}
\end{figure}
%%%%%%%%%%%%End of figure-Title%%%%%%%%%%%%%%
(to be continued…)
Add comment September 4, 2007
Howto… when network interface is missing
Sometimes, eth0 (or other devices) cannot be found or recognized after a reboot/NIC change. This is common after hardware replacement, or copying/modifying guest OS running on virtual machine (vmware, virtual PC).
Symptom
When trying to bring up the network interfaces, the following message (or similar) occurs:
SIOCSIFADDR: No such device
eth0: ERROR while getting interface flags: No such device
ifconfig displays the local loopback.
Problem
The reason for this is a change in MAC address. Linux OS recognition and configuration of an interface is assigned with the MAC address of this interface. If it changes while the OS is running (similar to hot-plug), OS will lose the information previously gathered for this device. This is more common in linux running on top of VMware and other vm, where guest OS is often suspended, then moved.
Solution
After searching on web, I found two posts related to the problem. One is to get back the lost interface, the other is to generate a new interface for virtual machine.
For ubuntu, the MAC address of each interface is stored at /etc/iftab, editing this file with the correct MAC you learn from elsewhere, and restart the network will do the trick. For VMWare, the generated MAC address is stored in *.vmx file. Click here for the original discussion.
If you want to add a new interface for VM, follow the vmx file sample given in this post.
Add comment March 16, 2007
Dah… Get rid of the annoying database lock
There have been several times that I had to kill the package management program while it was not through yet. In this case the lock of the database could not be removed correctly and further access to it is prohibited.
The problem is simple, but annoying. Plus, it is common especially when you have a fragile access to internet. So here is the solution when someone tells you ‘database is locked’ in ubuntu/debian linux using apt to manage packages.
Here it is, quoted from https://answers.launchpad.net/ubuntu/+ticket/2231
Use this command from konsole:
$ sudo fuser -vki /var/lib/dpkg/lock
This will ask you if you want to kill the process using the file.
Now you can run:
$ sudo dpkg –configure -a
to make sure all packages are fully installed.
Add comment March 12, 2007
How to improve my English
Recently I paid a three-week visit to California and chatted with dozens of people on all occasions. Although It has been many years since I said my ABC, this was the first time for me to live in an English-dominating environment. And I got some clues on further improvement of my English.
Accent
Nonnative speakers can well sense that they speak differently. The point is to know how and why this happens. For example, Chinese often pronounce ‘that‘ as ‘zat‘, ‘thought‘ as ‘sought‘, because Chinese (including those speak mandarin and dialects) never put their tongue between their teeth. We tend to neglect, or pronounce poorly, phoneme not existing in our mother tongue. On the other hand, Chinese do have much more complex intonation systems, and they affect the way we speak English. The biggest effect is that we often replace a down tone with a flat tone, which is common in Chinese. Paying special attention to phoneme that are absent in my first language and eliminating tones not popular in English are two key points of eliminating accent.
Vocabulary
During my several flights, there were plenty of chances to chat around with native English speakers. I was upset to realize that my vocabulary could hardly support a dialog beyond everyday life. I cannot master less popular, but important phrases or words barely through learning the language itself. It is the lack of systematic education in English. Therefore, the ability to talk like an well-educated English speaker requires formal education in English. It could be a time-consuming plan, but must help a lot if one goes through textbooks from grade 1 to 12 in the next 3 years. I believe it will significantly boost my proficiency of English, let’s see.
2 comments December 21, 2006
Shot their own feet
Live Mail filtered Microsoft Survey invitation as junk. I lost a teeny-tiny chance to win in a sweepstakes. Oh well… Do we have to take training courses in “how to compose emails in a junk-unlikely style” someday in the future?
Add comment March 4, 2008