Skip to content

Commit 429ffc3

Browse files
committed
More opencl info
1 parent 39fed92 commit 429ffc3

9 files changed

Lines changed: 85 additions & 24 deletions

File tree

c/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include <time.h> /* time() */
2020
#include <wchar.h>
2121
#if __STDC_VERSION__ >= 199901L
22-
/* Not yet implemented in GCC 4.8. */
23-
/*#include <thread.h>*/
22+
/* Not yet implemented in GCC 5.2. */
23+
/*# include <threads.h>*/
2424
# ifndef __STDC_NO_COMPLEX__
2525
# include <complex.h>
2626
# endif

cpp/interactive/thread_count.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Dummy operation that uses a lot of CPU, but very little memory.
3+
4+
Used as a control for the parallel version, which should me scalably faster.
5+
*/
6+
7+
#include "common.hpp"
8+
9+
void sleeper() {
10+
std::this_thread::sleep_for(std::chrono::seconds(1000000));
11+
}
12+
13+
int main() {
14+
unsigned int nThreads = std::thread::hardware_concurrency();
15+
std::thread *threads = new std::thread[nThreads];
16+
unsigned int i;
17+
for (i = 0; i < nThreads; ++i)
18+
threads[i] = std::thread(sleeper);
19+
for (i = 0; i < nThreads; ++i)
20+
threads[i].join();
21+
}

cpp/reference.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
# &
55
6-
Basically aliases, similar to `int* const` poinsters or java objects.
6+
Basically aliases, similar to `int* const` pointers or Java objects.
77
88
Useful only for function arguments or / return values. In that case the pros are:
99
@@ -15,13 +15,20 @@
1515
The cons are:
1616
1717
- callers don't know without looking at the signature if they are passing references or copies,
18-
and wether they should expect that it is possible that the functio modifies their object.
18+
and whether they should expect that it is possible that the function modifies their object.
1919
20-
Just like for pointers, you have to watch scope. If the original object dies,
21-
you get a dangling reference
22-
23-
- http://stackoverflow.com/questions/752658/is-the-practice-of-returning-a-c-reference-variable-evil
2420
- http://stackoverflow.com/questions/7058339/c-when-to-use-references-vs-pointers
21+
22+
# Return reference from function
23+
24+
Just like for pointers, you have to watch scope. If the original object dies,
25+
you get a dangling reference
26+
27+
- http://stackoverflow.com/questions/752658/is-the-practice-of-returning-a-c-reference-variable-evil
28+
29+
There is also some rule about const local references:
30+
31+
- http://stackoverflow.com/questions/2784262/does-a-const-reference-prolong-the-life-of-a-temporary
2532
*/
2633

2734
#include "common.hpp"

cpp/vector.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ int main() {
125125

126126
// Increase size
127127
{
128-
129128
// Using default constructor objects.
130129
{
131130
std::vector<int> v{1};

opencl/bibliography.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
- <http://developer.amd.com/tools-and-sdks/opencl-zone/opencl-resources/>
55
- <http://www.fixstars.com/en/opencl/book/OpenCLProgrammingBook>
66
- The specifications of your hardware, e.g. <http://www.nvidia.com/object/nvs_techspecs.html>
7+
8+
Tutorials with sample code:
9+
10+
- <https://github.com/sschaetz/nvidia-opencl-examples>
11+
- <https://github.com/enjalot/adventures_in_opencl> Did not work out of the box for me.
12+
- <https://github.com/bgaster/opencl-book-samples> The book is commercial.

opencl/getting-started.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,4 @@
22

33
## NVIDIA
44

5-
On Ubuntu 15.10 with an NVIDIA NVS 5400M, Lenovo T430:
6-
7-
sudo apt-get install nvidia-352 nvidia-352-dev nvidia-prime
8-
sudo ln -s /usr/include/nvidia-352/GL /usr/local/include
9-
sudo ln -s /usr/lib/x86_64-linux-gnu/libOpenCL.so.1 /usr/local/lib/libOpenCL.so
10-
11-
Then compile with:
12-
13-
gcc -o main main.c -lOpenCL
14-
15-
Notes:
16-
17-
- find your GPU model: <http://askubuntu.com/questions/72766/how-do-i-find-out-the-model-of-my-graphics-card>
18-
- test that the driver is working: <http://askubuntu.com/questions/68028/how-do-i-check-if-ubuntu-is-using-my-nvidia-graphics-card>
19-
- do not install the `nvidia-current` package. It is old. Either `apt-cache search nvidia` and get the latest one, or use `software-properties-gtk` "Additional Drivers" tab.
5+
On Ubuntu 15.10 with an NVIDIA NVS 5400M, Lenovo T430: <http://askubuntu.com/questions/541114/how-to-make-opencl-work-on-14-10-nvidia-331-89-drivers/693043#693043>

opencl/introduction.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,20 @@ Looks like the major open source implementation.
2626

2727
### pocl
2828

29+
Portable OpenCL implementation.
30+
2931
<https://github.com/pocl/pocl>
3032

3133
<http://portablecl.org/>
3234

3335
MIT and LLVM based.
36+
37+
## Tools
38+
39+
- <http://repo.or.cz/w/ppcg.git> C99 to OpenCL.
40+
41+
## Alternatives
42+
43+
- OpenMP: <http://stackoverflow.com/questions/7263193/opencl-performance-vs-openmp>
44+
- <https://en.wikipedia.org/wiki/Unified_Parallel_C>
45+
- <https://en.wikipedia.org/wiki/Cilk>

opengl/TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# TODO
22

33
- Are the OpenGL types fixed size? How to properly printf them?
4+
- How to select the rendering device? <http://stackoverflow.com/questions/6036292/select-a-graphic-device-in-windows-opengl> `prime-select`?

posix/interactive/pthread_count.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
To see if
3+
4+
./pthread_count.out &
5+
cat /proc/$!/status | grep -i thread
6+
kill $!
7+
8+
shows the right thread count.
9+
*/
10+
11+
#include "common.h"
12+
13+
void* main_thread(void *arg) {
14+
sleep(1000000);
15+
return NULL;
16+
}
17+
18+
int main() {
19+
int i;
20+
enum NUM_THREADS {NUM_THREADS = 4};
21+
pthread_t threads[NUM_THREADS];
22+
for (i = 0; i < NUM_THREADS; ++i) {
23+
pthread_create(&threads[i], NULL, main_thread, NULL);
24+
printf("tid: %ju\n", (uintmax_t)threads[i]);
25+
}
26+
for (i = 0; i < NUM_THREADS; ++i) {
27+
pthread_join(threads[i], NULL);
28+
}
29+
}

0 commit comments

Comments
 (0)