Hi,
Recently, I tackled to setup Thrust programming environment on Visual
Studio 2012 + my 64-bit Windows 7 desktop. It was surprisingly complicated
to me, and the information on the Net was sometimes confusing (to me ...).
So, I wrote a memo and wanted to share it with people who are concerned
with GPU acceleration of Nupic.
If you're already familiar with this information, please ignore this spam.
Otherwise, I hope it's useful...
Best Regards,
Hideaki Suzuki.
---------------------------------------------------------------------
How to setup CUDA + Thrust environment on Windows7 64-bit OS
---------------------------------------------------------------------
September 10, 2013
Hideaki Suzuki
1. Install the following software on Windows7 64-bit OS
- Visual Studio 2012 Professional (full installation)
- CUDA Development Kit 5.5.20(cuda_5.5.20_winvista_win7_win8_general_64.exe)
Note:
Visual Studio Express 2012 has issues to build a 64-bit CUDA program.
It is okay as long as you use OpenMP backend for thrust without GPU,
or stay with 32-bit. Windows SDK might help, but I didn't try.
2. On VS2012
Tool > Option > Text editor > File extension
Add "cu" and "cuh" as Microsoft Visual C++
3. Create a new Win32 Console App for your testing.
4. Right click your solution on Solution Explorer
Go to Build Customization
> Check CUDA 5.5(.targets, .props)
Go to Properties
> Configuration Properties
Add Platform "x64"
5. Right click your project on Solution Explorer
Go to Properties
> Check Platform "Active(x64)" is selected.
> CUDA C/C++ > Common
Target Machine Platform: 64-bit (--machine 64)
> CUDA C/C++ > Device > Code Generation
compute_20,sm_21
Note:
"compute_20,sm_21" means compute capability 2.1
compute capability depends on your GPGPU card.
ref. https://developer.nvidia.com/cuda-gpus
If you don't set the right compute capability,
You will receive a runtime exception at thrust::system::system_error
after you start the program.
ref.
http://stackoverflow.com/questions/15289030/thrustsystemsystem-error-in-transform-reduce
> CUDA C/C++ > Host > Preprocessor Definitions
_SCL_SECURE_NO_WARNINGS
Note:
Without _SCL_SECURE_NO_WARNINGS, Error C4996 will be generated for
the use of
strerror() in Thrust.
> CUDA C/C++ > Command Line > Additional Options (the input box at
the bottom)
-Xcompiler "/wd 4819"
Note:
This setting suppresses a number of false-alert warnings related to
code page.
6. Add test.cu under "Source Files" on Solution Explorer
Note:
The name must end with ".cu" to be processed by nvcc compiler.
If you specify ".cpp", nvcc just passes it to the host compiler
without processing it.
7. Right click test.cu
Go to Properties and verify
> General > Item Type
CUDA C/C++
8. Start writing test.cu with the following lines.
----------------------------
#include "stdafx.h" // This is the
precompile header.
#pragma comment(lib, "cudart") // This instructs VS2012 to link with
CUDA runtime
----------------------------
Here is a sample program using Thrust.
test.cu:
=============================================================
#include "stdafx.h"
#pragma comment(lib, "cudart")
/*
* In case to use OpenMP backend instead of CUDA (without a graphic card)
* 1. rename test.cu to test.cpp
* 2. test.cpp's property > General > Item Type > C/C++ compiler.
* 3. Project's Property > C/C++ > Language > Open MP Support
* 4. uncomment the following #define line.
* 5. clean & rebuild the project.
*/
//#define THRUST_DEVICE_SYSTEM THRUST_DEVICE_SYSTEM_OMP
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/reduce.h>
#include <algorithm>
#include <iostream>
void test_thrust(void)
{
std::cout << "starting test.cu ..." << std::endl;
std::cout << "ptr size: " << sizeof(void *) << std::endl;
std::cout << "int size: " << sizeof(int) << std::endl;
std::cout << "size_t size: " << sizeof(size_t) << std::endl;
// generate random data serially
thrust::host_vector<int> h_vec(100);
std::generate(h_vec.begin(), h_vec.end(), rand);
// transfer to device and compute sum
thrust::device_vector<int> d_vec = h_vec;
int x = thrust::reduce(d_vec.begin(), d_vec.end(), 0,
thrust::plus<int>());
std::cout << "sum: " << x << std::endl;
}
=============================================================
main.cpp:
=============================================================
#include "stdafx.h"
#include <iostream>
extern void test_thrust(void);
int main(void)
{
std::cout << "ptr size: " << sizeof(void *) << std::endl;
std::cout << "int size: " << sizeof(int) << std::endl;
std::cout << "size_t size: " << sizeof(size_t) << std::endl;
test_thrust();
return 0;
}
=============================================================
9. Build the program.
You will see a few warnings of C4267, because thrust assigns size_t to int.
For 64-bit VS compiler, size_t and pointer are 8 bytes, while int is 4 bytes.
If you want to suppress the warning, you can specify at Step.5 above:
-Xcompiler "/wd 4819 /wd 4267"
10. Run the program.
Ctrl-F5 will probably give you the following output.
=============================================================
ptr size: 8
int size: 4
size_t size: 8
starting test.cu ...
ptr size: 8
int size: 4
size_t size: 8
sum: 1621348
=============================================================
END.
_______________________________________________
nupic mailing list
[email protected]
http://lists.numenta.org/mailman/listinfo/nupic_lists.numenta.org