본문 바로가기

Wisdoms131

[c++] thread-safety of vector<bool> vector 형태는 thread-safe 하지 않다. 그러므로, 병렬화가 필요하다면, 반드시 bool 배열을 사용하자. 물론 큰 배열이 필요하다면, heap에 배열을 생성하고, 배열이 stack에 들어갈 수 있으면 local 배열로 선언하여 이용하자. 2015. 6. 16.
[cuda] scan scan은 cumulative 연산이다.exclusive cumulative sum은 다음과 같이 구현된다. exclusive는 현재 요소는 포함하지 않음을 나타낸다. op 부분은 sum 연산자로 대체된다. identity()는 해당 연산에 대해서 입력과 동일한 결과를 주는 파라미터의 값이다. sum의 경우에는 0이다. 가령, 1+0 = 1. int acc = identity(); for (int i = 0; i < elements.size(); ++i) { acc = acc op elements[i]; out[i] = acc;} 만약 위의 for loop 안의 순서를 바꾸게 되면, inclusive cumulative sum이 된다.exclusive는 가령 [1, 2, 3, 4] 가 있으면,[0, 1,.. 2015. 6. 14.
[cuda] udacity cs344 숙제 2 - student_func.cu // Homework 2// Image Blurring//// In this homework we are blurring an image. To do this, imagine that we have// a square array of weight values. For each pixel in the image, imagine that we// overlay this square array of weights on top of the image such that the center// of the weight array is aligned with the current pixel. To compute a blurred// pixel value, we multiply each pair of numbers t.. 2015. 6. 14.
[cuda] udacity atomic add 관련 코드 #include #include "gputimer.h" #define NUM_THREADS 10000000#define ARRAY_SIZE 100 #define BLOCK_WIDTH 1000 void print_array(int *array, int size){ printf("{ "); for (int i = 0; i < size; i++) { printf("%d ", array[i]); } printf("}\n");} __global__ void increment_naive(int *g){// which thread is this?int i = blockIdx.x * blockDim.x + threadIdx.x; // each thread to increment consecutive elements, .. 2015. 6. 14.