How to install Theano on Mac OS X EI Capitan with OpenCL support

I have two Mac, a Mac pro and Macbook pro. They both use AMD display card, so I can’t use CUDA speed up machine learning, so I want to use OpenCL.

First install some requirements:

Then make install environment ( use virtualenv can make everything easy ):

Install Theano:

Then you can use this demo code ( ) to test your Theano:

This test will show something like this:

It just do some math 1000 time, took 1.492254 seconds, and use cpu.

Then we must install libgpuarray to make Theano support OpenCL:

Then we can use THEANO_FLAGS to set use OpenCL device.

Use OpenCL & Cpu in my Mac pro:

Note: Code showed “Used the gnu”, but as you can see, this was using CPU.

Use OpenCL & GPU 1 in My Mac pro:

Finally, we can use OpenCL and GPU.


My Mac pro

屏幕截图 2016-04-01 15.09.25

My Macbook pro

屏幕截图 2016-04-01 15.09.32

Note: Now we can use Theano and OpenCL. But I was very sad, when I found out Theano is using CUNN, so when you use Theano to do Neural Network, we still need CUDA support. Just for now I don’t know how to solve this problem.

Chinese version of this article.

Before you install Tensorflow on your Mac or your AWS, you must know !!

Recently I started playing Tensorflow on my mac, it very fun. But I found there are some traps about Tensorflow on Mac and AWS, so tell you know.

  1. Tensorflow is very slow.
  2. Now Tensorflow doesn’t support CUDA on Mac officially, but you can easy find a way to compile it to support CUDA. But almost all new Mac don’t contain a NVIDIA display card, so you still can’t use CUDA. OpenCL support is on the way, open to contributions, but how knows.
  3. The HPC of AWS ( g2.2xlarge
    and g2.8xlarge ) contain NVIDIA display card, but the card is blow the requirement of default CUDA setting of Tensorflow, so you can’t user precompiled Tensorflow, you need compile it by yourself, and set compute capability is 3.0. And there is a AMI (Amazon Linux x64 AMI with TensorFlow (GPU)), already include Tensorflow on AWA’ AMI market, but this AMI is using precompiled Tensorflow, so it is useless, you can’t use the GPU. And even after your compile and install you own Tensorflow, there is a bug of NVIDIA display driver card, you must update NVIDIA display card driver, and finally you can use GPU from the HPC.

How to record audio use Swift

Apple Xcode documents reading guide

The structure of Xcode documents


As above, when you open Xcode documents, the whole interface build by left side area, and right side content area. You can choose different documents sets from left side area. Normally your Xcode documents includes some iOS documents sets, some Mac OS X documents sets, and a Xcode documents set.

If the documents set you want isn’t available here, you can choose Preferences menu of Xcode, the choose Downloads -> Documentation. You can find installed documents sets, undownloaded documents sets, you can free choose what you want. Like blow:


Then look at left side of the content are, this is the structure of a documents set, as blow:


First is Resource Types, all the articles in documents set must be one of the types:

  1. Getting Started — It is for the totally beginner. Recommend all beginners read them, there are some articles to help you establish the basic concepts, will make your next steps more easier.
  2. Guides — It is the best part of the documents, if you know how to read guides, you don’t need buy any books. Guides of Xcode documents, is a kind of step by step articles, tell you how to solve a problem, how to use a framework of Cocoa, how to understand the system, and so on. Programmers are familiar with reference, it is just like a dictionary. But reference normally is fragment knowledge, you need something to connect the dots, to get the big picture, guides will help you to do it.
  3. Reference — It is just like a dictionary, when you try to find detail information of a class, a method or a function, you look at their reference pages.
  4. Release Notes — It will tell you what is new in a new iOS/Mac version, the new features, new APIs, new way to do something. When you try to learn new system, compare different APIs in different version, you may want check them.
  5. Sample Code — Apple provide a lot of codes, help you understand APIs and technologies. Strong Recommend you look into them. Sometimes if you only read documents, you can’t get everything. And all these codes is written by Apple engineers, you can learn from masters, and follow the trends of code style.
  6. Technical Notes — There are a lot of technical articles, you may want read it when you have some free time.
  7. Technical Q&A — Frequently asked questions and answers.
  8. Video — Mainly WWDC videos. Strong Recommend you watch, if you want to dig deeper.

Normally reference, release notes, sample code, technical notes and Technical Q&A,is for you to search. Getting started and guides is for you to read.

Then is the topics:

  1. Audio & Video
  2. Languages & Utilities
  3. Mathematical Computation
  4. Xcode
  5. Data Management
  6. General
  7. Graphics & Animation
  8. Networking & Internet
  9. Performance
  10. Security
  11. User Experience

It is very easy to understand.

Then it is the Frameworks:

  1. Cocoa Touch Layer
  2. Media Layer
  3. Core Services Layer
  4. Core OS Layer

Types, topics and frameworks is three different dimensions to help understand and locate the documents you want.

Now look at the right of content area. On the top is a document filter, as blow:


For example, if you want read guides about performance, you may want select Topics -> Performance from the left side, then type “Guides” in the document filter. Or you can select Resource Types -> Guides from left, and type Performance in the document filter.

How to read guides

Reading orders:

  1. Start Developing iOS Apps Today
  2. Your First iOS App
  3. Your Second iOS App: Storyboards
  4. Your Third iOS App: iCloud
  5. iOS Technology Overview
  6. iOS Human Interface Guidelines
  7. Learning Objective-C: A Primer
  8. Programming with Objective-C
  9. iOS App Programming Guide
  10. View Programming Guide for iOS
  11. View Controller Programming Guide for iOS
  12. Table View Programming Guide for iOS

You may want start with “Start Developing iOS Apps Today“, this is a very easy article, but it will help you establish the basic concepts. All the concepts you will meet when you develop your app, you can find in it. And all the articles in the “related articles” section in the bottom of every page, is needed to read.

A lot of iOS developers, even long time developers, have some misunderstandings about some basic concepts. Modern developing is easier and easier, tools are stronger and stronger, even when you have some misunderstandings, you can still do some works. But if you don’t build a solid foundation, you will be hurt by it soon, it will cause a lot of trouble.

Purpose and test standard is that you understand most of the concepts in your development works.

Then you may want read “Your First iOS App“, “Your Second iOS App: Storyboards“, and “Your Third iOS App: iCloud“, this series is easy too. You don’t need rush to learn Objective-C/Swift. The method I recommended is step by step. Before you learn system structure, Objective-C/Swift, you can follow the articles, write a simplest App, as your first milestone. During the process, you don’t need worry about any questions, any misunderstanding, just do it first.

This process will help you understand the development tools, Xcode and so on, and give you confidence.

Purpose and test standard is write these three Apps, and build and run them using Xcode.

Then you may want read “iOS Technology Overview“, iOS is not a technology, it is a set of a lot of technologies. When you want an animation effect, you need know you which technology you can choose and which one you should choose, Core Animation or OpenGL? When you want to some work related text, if you need Core Text or not? Want understand this kind problems, you need read this article.

Learn modern programming language, framework is as important as language itself. Only when you understand the frameworks structures, then you can easily find what you want when you work.

Purpose and test standard is that you know where to find you information about frameworks.

Then you must read iOS Human Interface Guidelines. There are a mass of all kinds Apps on Mac/iOS, but normally you will find good Apps are familiar and harmonious with the system. Not like Windows or other platforms, why?

It is the “Human Interface Guidelines” culture’s credit. In these articles, Apple talk about what is the best manners of an App, how do you do in your App, to make use feel familiar and harmonious. Apple even give “Human Interface Guidelines” an abbreviation HIG, if you follow HIG, your Apps will look like a Mac/iOS App, act like a Mac/iOS App. You can break HIG, but must after you truly understand it, and follow its spirit.

And read HIG can help you understand UI structures and how UI elements interact each other, so you can design your UI.

Purpose and test standard is when you look at an app, you can identify which part is system controller, which is a self custom controller, and their levels, structures.

Then you may want read “Learning Objective-C: A Primer“, this is the easy one, and the more complex one, “Programming with Objective-C”.

Most people learn language first and recommend this order, but I recommend understand basic concepts first, then make a demo App, then learn the language.


  • Modern development normally involve UI interactive and IDE, beginner can not ignore them. You must know you tools, and your problem fields.
  • Modern language, normally is combine with some lirbaries, sometimes lirbaries are more important than the language, and more complex.

For example, Delegate and Block are very close to Cocoa UI’s asynchronous mechanism, if you don’t know UI mechanism, you hardly can understand these language elements, or understand their usages.

Purpose and test standard is knowing how to read Objective-C codes.

Then “iOS App Programming Guide”, talk about a complete process of how to develop an App, include App’s lifecycle, execution States, and so on. Must read before you develop you first real app.

Purpose and test standard is knowing a lot of processes and details.

View Programming Guide for iOS and View Controller Programming Guide for iOS are very important. View is the most important concept in iOS/Mac UI. All graphs, UI is based on view. UI no matter how complex normally is built by view, is all kinds of combinations and overlaps of views.

View Controller is view combine with logic codes, this kind combination will remarkably reduce code complexity. You can hardly write correct without knowing View and View Controller.

Purpose and test standard is knowing View and View Controller, and knowing in which circumstance use view, which use view controller.

UITableView is the most important controller, is most useful UI element. Before UICollectionView, most custom list/grid controller is made by UITableView. So read Table View Programming Guide for iOS is very important.

Purpose and test standard is understand UITableView and UITableViewController, knowing how to use them.

After read these articles, you may already can say you know how to write an iOS App. But you almost can read all these articles in one day. It is not very hard, but need some patience, need follow the right method, and need think.

How to find information in documents

Quick Help

The most convenient way to get help even don’t need you type a word. You just need hold Option key, and click the keyword you want to know, you will immediately get quick help, like blow:


Quick help will includes some simple description, available from which version of OS, header file, and reference document. Header file and reference document is clickable.

Even your keyword is not a keyword of Cocoa library, is just a class name or method name from your own codes, you can also get some information, like this:


Another hotkey is Command key + mouse click, editor will just to head files related with a class name or method name.

Another way to get quick help information is to use Quick help inspector, first find the Utilities switch, and find the Quick help inspector switch. Like this:


It function is as long as opened, whichever keyword your input caret at, Quick help inspector will show its information, just like the information from Option key + mouse click, but maybe more rich.

Search documents

This is search interface, when we search UIImage:


The results is also divided in four types, Reference, System Guides, Tools Guides and Sample Code.

How to read a reference

This is UIImage’s reference:



  1. Inherits from
  2. Conforms to
  3. Framework
  4. Availability
  5. Declared in
  6. Related sample code
  7. Companion guide

And it maybe not very clear, on the top of the interface, it is a navigation bar, you can use it to navigate to different places.

Can we use Swift as a backend language?

First question is why someone need use Swift as a backend language? I think:

  1. People always seek to use one language solves all kinds of problem. If Swift can use as a backend language, iOS developers can easily change their identities to Full Stack developer. They can use one language to make a whole product iOS client and server.

  2. Beside UI-related classes, Cocoa-touch have a lot of other things. iOS developers can reuse a lot of Cocoa-touch frameworks and a lot of third party frameworks, and a lot of source bases from their iOS codes.

  3. Swift use ARC (Automatic Reference Counting) manage memory, fast, efficient, easy to use. ARC is more convenient than manually manage memory (C/C++), and more efficient and fast than GC (Java/C#).

  4. The typing system of Swift can make server side codes safer.

Finally can we use Swift as a backend language? It depends:

  1. To be a good backend language, Swift needs Apple or third party provide a lot of frameworks for backend usage.

  2. Swift may need some language support to handle concurrent connections.

How to capture web page to image on Linux server

Yesterday, I was trying to add a new function to my bbs, I needed something help me capture web page to image on my Linux server. So I did some research, found out that CutyCapt can be used to solve this problem.

Install steps:

but I didn’t know why, it can’t be compiled, we need to modify CutyCapt.hpp, add the lines below to the top of the file.x

Now, everything is fine.

The oc.png will be your result file, but I found that, everything is ok, when you capture English sites. If you want to capture Chinese or Japanese, you will found the chinese or Japanese words will be show as some kind of little boxes. This is because your linux don’t contain TTF Chinese fonts.

I use Google noto-cjk, you can install it:

Now Chinese and Japanese sites are very clear and beautiful.

Even if you don’t believe forever, you need keep going forward, even you don’t have the future, you shouldn’t give up present

If you have never any fear, how can you talk about brave. If anything is as you wish, how can you talk about facing life.

From the perspective of probability, most people cannot find forever love, isn’t it means that we have to give up to pursue? I believe everybody has his answer.

The world is very imperfect, there are plenty of problems, we all are imperfect, we all have problems. But, so what?

If you depend on that you can easily solve every problem, you are more vulnerable.

The imperfectness of the world, just like a light house far away, and very bright, it gives you a direction, so you know you can never reach it, but you can keep going forward. Just like our imperfectness.

Start from accepting ourself and accepting present.