Programming/openCL & CUDA2014. 1. 14. 19:53
visual studio 2008 / cuda 5.5 / GTX650 기준 작성

    0 a:26326 b:14567 c:40893 == r:40893
    1 a:20769 b:29469 c:50238 == r:50238
    2 a:19293 b:19828 c:39121 == r:39121
    3 a: 5720 b:16164 c:21884 == r:21884
    4 a:10116 b:16010 c:26126 == r:26126
    5 a:24503 b: 1380 c:25883 == r:25883
    6 a: 1261 b:20500 c:21761 == r:21761
    7 a:32527 b:14265 c:46792 == r:46792
    8 a: 6165 b: 1639 c: 7804 == r: 7804
    9 a:16881 b: 7619 c:24500 == r:24500
   10 a:14636 b: 3016 c:17652 == r:17652
   11 a:20766 b: 1675 c:22441 == r:22441
   12 a:24356 b: 3886 c:28242 == r:28242
   13 a: 9279 b:15721 c:25000 == r:25000
   14 a:20744 b:   74 c:20818 == r:20818
   15 a:24023 b:17957 c:41980 == r:41980
   16 a:  399 b:19653 c:20052 == r:20052
   17 a: 9077 b: 9308 c:18385 == r:18385
   18 a:18673 b:  713 c:19386 == r:19386
   19 a:17966 b:12837 c:30803 == r:30803
   20 a:28921 b:31938 c:60859 == r:60859
   21 a:20298 b:18933 c:39231 == r:39231
   22 a:18267 b:31334 c:49601 == r:49601
   23 a:17726 b:18368 c:36094 == r:36094
   24 a:10825 b:19187 c:30012 == r:30012
   25 a:15579 b: 9569 c:25148 == r:25148
   26 a:17217 b:27831 c:45048 == r:45048
   27 a: 2756 b:13884 c:16640 == r:16640
   28 a:25641 b:17878 c:43519 == r:43519
   29 a:10533 b:17954 c:28487 == r:28487
   30 a:15005 b:23112 c:38117 == r:38117
   31 a: 9634 b: 8053 c:17687 == r:17687 


#include < stdio.h >
#include < stdlib.h >
#include < time.h >

#include "cuda_runtime.h"

#define ARRAY_SIZE	32

__global__ void kernel_test(int *a, int *b, int *c)
{
	int idx = threadIdx.x;
	c[idx] = a[idx] + b[idx];
}

void main()
{
	int a[ARRAY_SIZE],b[ARRAY_SIZE],c[ARRAY_SIZE],res[ARRAY_SIZE];
	int *dev_a,*dev_b,*dev_c;
	int idx = 0;
	dim3 block(1);
	dim3 thread(ARRAY_SIZE);

	// initialize
	srand (time(NULL));
	for(idx = 0;idx < ARRAY_SIZE ; idx++)
	{
		a[idx] = rand();
		b[idx] = rand();
		res[idx] = a[idx] + b[idx];
		c[idx] = 0;
	}

	cudaMalloc(&dev_a, ARRAY_SIZE * sizeof(int));
	cudaMalloc(&dev_b, ARRAY_SIZE * sizeof(int));
	cudaMalloc(&dev_c, ARRAY_SIZE * sizeof(int));

	cudaMemcpy(dev_a, a, ARRAY_SIZE * sizeof(int), cudaMemcpyHostToDevice);
	cudaMemcpy(dev_b, b, ARRAY_SIZE * sizeof(int), cudaMemcpyHostToDevice);

	kernel_test<<<block,thread>>>(dev_a,dev_b,dev_c);

	cudaMemcpy(c, dev_c, ARRAY_SIZE * sizeof(int), cudaMemcpyDeviceToHost);

	for(idx = 0;idx < ARRAY_SIZE ; idx++)
	{
		printf("%5d a:%5d b:%5d c:%5d", idx, a[idx], b[idx], c[idx]);
		if(res[idx] != c[idx])
				printf(" != ");
		else	printf(" == ");
		printf("r:%5d\n",res[idx]);
	}

	cudaFree(dev_a);
	cudaFree(dev_b);
	cudaFree(dev_c);
}


#define ARRAY_SIZE	64

__global__ void kernel_test(int *a, int *b, int *c)
{
	int idx = threadIdx.x + threadIdx.y * 8;
	c[idx] = a[idx] + b[idx];
}

void main()
{
	dim3 block(1);
	dim3 thread(8,8);
}

'Programming > openCL & CUDA' 카테고리의 다른 글

visual studio 2008 nsight 실행..된거 맞나?  (0) 2014.01.15
nsight 설치... -_-  (0) 2014.01.15
cuda 5.5 조금은 더 빠르게 컴파일 하기  (0) 2014.01.14
GTX650 / ion devicequery  (4) 2014.01.13
cuda dim3 변수 초기화  (0) 2014.01.13
Posted by 구차니
Programming/openCL & CUDA2014. 1. 14. 17:14
vs2008의 문제인지 cuda5.5의 변경점인지 모르겠지만
컴파일시 하나의 파일에 대해서 경고가 여러번 뜨는 것 봐서는
여러번의 컴파일을 시도하는 것으로 생각되어 프로젝트 옵션을 뒤져보고 대충 테스트 해본결과

기본값으로 GPU Architecture가 sm_10과 sm_20 두개가 설정이 되어 있어 2번의 컴파일을 수행하고 있었다.
그래픽 카드의 아키텍쳐를 확실히 안하면 제대로 설정해서 한번만 컴파일 하는 것도
컴파일 시간 단축에 도움이 많이 될 듯 하다.

1,2에 sm_10 / sm_20을

 
GTX650을 쓰고 있으니 sm_30으로 설정!

 

'Programming > openCL & CUDA' 카테고리의 다른 글

nsight 설치... -_-  (0) 2014.01.15
cuda 1 block 1차원 & 2차원 thread 예제  (0) 2014.01.14
GTX650 / ion devicequery  (4) 2014.01.13
cuda dim3 변수 초기화  (0) 2014.01.13
vs2008 cuda syntax highlight  (0) 2014.01.13
Posted by 구차니
Programming/openCL & CUDA2014. 1. 13. 22:12
가장 중요한 차이점 아래 스샷 참조
왼쪽이 ion 오른쪽이 GTX650 이다.


전체 비교


사이즈 문제로 텍스트 버전은 아래에


Posted by 구차니
Programming/openCL & CUDA2014. 1. 13. 17:58
dim3는 uint3 형(unsigned int)으로 x,y,z 3개의 변수를 지니는 구조체다.
c++ 스타일과 c 스타일로 초기화가 각각 가능하며

C++ 스타일로는
dim3 valname(x,y,z);
dim3 valname(x,y);
dim3 valname(x); 
식으로 값이 없는 건 1로 선언되며

C 스타일로는
dim3 valname = {x,y,z};
으로 선언된다.

---
엥? c 스타일로는 선언 안되는데?
dim3 testdim3 = {1,1,1};
dim3 testdim2 = {1,1}
dim3 testdim1 = {1} 

error: initialization with "{...}" is not allowed for object of type "dim3"
error: initialization with "{...}" is not allowed for object of type "dim3"
error: initialization with "{...}" is not allowed for object of type "dim3" 
---

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include\vector_types.h
struct __device_builtin__ dim3
{
    unsigned int x, y, z;
#if defined(__cplusplus)
    __host__ __device__ dim3(unsigned int vx = 1, unsigned int vy = 1, unsigned int vz = 1) : x(vx), y(vy), z(vz) {}
    __host__ __device__ dim3(uint3 v) : x(v.x), y(v.y), z(v.z) {}
    __host__ __device__ operator uint3(void) { uint3 t; t.x = x; t.y = y; t.z = z; return t; }
#endif /* __cplusplus */
};

typedef __device_builtin__ struct dim3 dim3;

[링크 : http://choorucode.com/2011/02/16/cuda-dim3/]
Posted by 구차니
Programming/openCL & CUDA2014. 1. 13. 10:49
vs2005가 VS8 인데 이녀석으로 vs2008/VS9에 덮어 씌우며 된다.
usertype.dat 파일은 아래의 경로에 있는데 UUID가 들어가서 사용자 마다 다르게 추가될 가능성이 있다.

usertype.dat 파일을
C:\Program Files\NVIDIA Corporation\Installer2\CUDASamples_5.5.{5B964E0E-AB97-450D-9C30-C390798C19EB}\doc\syntax_highlighting\visual_studio_8\usertype.dat

아래의 경로에 복사한다.
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\usertype.dat

readme.txt
Want pretty syntax highlighting when editing your .cu files in Visual Studio?
Here's how:

---
Visual Studio .Net 2005 / Visual Studio 8:

1. If you don't have a usertype.dat file in your "Microsoft Visual Studio 8\Common7\IDE" folder, then copy the included usertype.dat file there.  If you do, append the contents of the included usertype.dat onto the end of the "Microsoft Visual Studio 8\Common7\IDE\usertype.dat"

2. Start Visual Studio 8.  Select the menu "Tools->Options...".  Open "Text Editor" in the tree view on the left, and click on "File Extension".  Type cu in the "Extension" box, set the editor to "Microsoft Visual C++" and click "Add".  Click "OK" on the dialog box.  

3. Restart Visual Studio and your CUDA code should now have syntax highlighting. 

그리고는 Visual Studio의 도구 - 옵션 - 텍스트 에디터에서


파일 확장명에 cu를 축가하고 편집기를 "Microsoft Visual C++"으로 선택후 적용하면 된다.


dim3 타입까지 색상이 들어가는 것을 확인!


[링크 : http://stackoverflow.com/questions/5077104/how-can-i-get-syntax-highlighting-for-a-cu-file-in-visual-studio]

'Programming > openCL & CUDA' 카테고리의 다른 글

GTX650 / ion devicequery  (4) 2014.01.13
cuda dim3 변수 초기화  (0) 2014.01.13
VS2008 + cuda5.5 프로젝트 생성  (0) 2014.01.13
nvidia ion + ubuntu 12.04 LTS + cuda5.5  (0) 2014.01.08
cuda on windows 7  (0) 2014.01.06
Posted by 구차니
Programming/openCL & CUDA2014. 1. 13. 10:23
예전에는 복잡하게 룰을 추가해야 했는데
2011/01/04 - [Programming/openCL / CUDA] - Visual Studio 2008 에서 CUDA 프로젝트 만들기

기본 템플렛이 추가 되어 있어서 편리하게 만들수 있다.


그런데.. 기본적으로 5개 짜리 더하는 예제가 추가되는건가?
#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include < stdio.h >

cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size);

__global__ void addKernel(int *c, const int *a, const int *b)
{
    int i = threadIdx.x;
    c[i] = a[i] + b[i];
}

int main()
{
    const int arraySize = 5;
    const int a[arraySize] = { 1, 2, 3, 4, 5 };
    const int b[arraySize] = { 10, 20, 30, 40, 50 };
    int c[arraySize] = { 0 };

    // Add vectors in parallel.
    cudaError_t cudaStatus = addWithCuda(c, a, b, arraySize);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "addWithCuda failed!");
        return 1;
    }

    printf("{1,2,3,4,5} + {10,20,30,40,50} = {%d,%d,%d,%d,%d}\n",
        c[0], c[1], c[2], c[3], c[4]);

    // cudaDeviceReset must be called before exiting in order for profiling and
    // tracing tools such as Nsight and Visual Profiler to show complete traces.
    cudaStatus = cudaDeviceReset();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceReset failed!");
        return 1;
    }

    return 0;
}

// Helper function for using CUDA to add vectors in parallel.
cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size)
{
    int *dev_a = 0;
    int *dev_b = 0;
    int *dev_c = 0;
    cudaError_t cudaStatus;

    // Choose which GPU to run on, change this on a multi-GPU system.
    cudaStatus = cudaSetDevice(0);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?");
        goto Error;
    }

    // Allocate GPU buffers for three vectors (two input, one output)    .
    cudaStatus = cudaMalloc((void**)&dev_c, size * sizeof(int));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        goto Error;
    }

    cudaStatus = cudaMalloc((void**)&dev_a, size * sizeof(int));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        goto Error;
    }

    cudaStatus = cudaMalloc((void**)&dev_b, size * sizeof(int));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        goto Error;
    }

    // Copy input vectors from host memory to GPU buffers.
    cudaStatus = cudaMemcpy(dev_a, a, size * sizeof(int), cudaMemcpyHostToDevice);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }

    cudaStatus = cudaMemcpy(dev_b, b, size * sizeof(int), cudaMemcpyHostToDevice);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }

    // Launch a kernel on the GPU with one thread for each element.
    addKernel<<<1, size>>>(dev_c, dev_a, dev_b);

    // Check for any errors launching the kernel
    cudaStatus = cudaGetLastError();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "addKernel launch failed: %s\n", cudaGetErrorString(cudaStatus));
        goto Error;
    }
    
    // cudaDeviceSynchronize waits for the kernel to finish, and returns
    // any errors encountered during the launch.
    cudaStatus = cudaDeviceSynchronize();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus);
        goto Error;
    }

    // Copy output vector from GPU buffer to host memory.
    cudaStatus = cudaMemcpy(c, dev_c, size * sizeof(int), cudaMemcpyDeviceToHost);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }

Error:
    cudaFree(dev_c);
    cudaFree(dev_a);
    cudaFree(dev_b);
    
    return cudaStatus;
}

'Programming > openCL & CUDA' 카테고리의 다른 글

cuda dim3 변수 초기화  (0) 2014.01.13
vs2008 cuda syntax highlight  (0) 2014.01.13
nvidia ion + ubuntu 12.04 LTS + cuda5.5  (0) 2014.01.08
cuda on windows 7  (0) 2014.01.06
cuda / cpu 테스트 드라이브  (0) 2014.01.06
Posted by 구차니
Programming/processing2014. 1. 12. 22:23
오랫만에 다시 들을 기회가 있어서
프로세싱을 받아서 실행해보니.. 과거의 칙칙한 연두색에서 벗어나
산뜻한 디자인으로 변경되었다.
2011/12/29 - [embeded/ATmega/ATtiny (AVR)] - 아두이노 (arduino)



getting start에서 복사한 코드로 대충 실행
setup() 과 draw() 두개의 함수가 존재할 뿐인데 이렇게 창이 생기고 그림이 그려지다니!!


웬지 마음에 드는 'copy as HTML' 


상단의 Java를 눌러 Add Mode를 하면 이런게 뜨는데..
java가 아닌 다른걸 통해서도 실행을 하게 하는 걸려나?


+
심심해서 Mode Manager에서 JavaScript Mode를 추가하고 재실행


Java 대신 JavaScript 로 변경후 Run!


웹 브라우저가 뜨면서 Java 애플릿을 통해 실행되는 것.. .같다?
(일단 브라우저 경고를 띄우니...) 





초기 버전에는 jre가 포함이었는지 설치가 되어서 그냥 썼는지
독립적으로 그린건지 기억이 안나서.. 비교가 불가
아무튼.. 우분투에서도 java를 설치하는 것 봐서는 기본적으로 java를 이용해 그리는것 같다.
[링크 : http://www.spacemig.com/2012/07/installing-processing-in-ubuntu-12-04/]

[링크 : http://processing.org/download/?processing] 다운로드 
[링크 : http://processing.org/tutorials/gettingstarted/] getting start

'Programming > processing' 카테고리의 다른 글

프로세싱(언어)  (0) 2013.01.08
processing (언어)  (0) 2012.05.04
Posted by 구차니
집에서 성화를 해서 갔다 와봤는데
[링크 : http://www.kscv.org/] 행사 홈페이지

그닥.. 볼게 없다는 느낌?
입구에 3d 프린터 외에는 참관 업체들이 눈에 띄는게 없었고
[링크 : http://rokit.co.kr/] 3d 프린터
[링크 : http://www.fablab-seoul.org/] 3d 스캐너

그외에 즉석 구인/구직 부스는 업체 이름만 잔뜩 써있어서 
사전 조사 없이는 면접보기도 참.. 애매한 상황. 게다가 언어 장벽 끄아아 ㅠㅠ

아무튼, 돌아 다니면서 몇군데 눈에 들어온 곳 목록

TNV / safevisions 업체 홈페이지(안전운전 도우미)
[링크 : http://www.safevisions.com/]

하이펀 / mySen-MoCa (자이로+가속도 센서 기반 모션캡쳐 솔루션)
[링크 : http://hyfun.co.kr/]
Posted by 구차니
일단 계좌제가 아직 안된 관계로
자비로 하는데

다행히도 48만원 정도 하는거 20% 할인해서 38만 4천원에 수강
책값도 2.5만원 정도 지원해준다고 하니 웬지 이득보는 느낌?

근데.. 내가 필요로 하는 기능/능력을 이걸 통해서 배울수 있는지가 미지수니까..
그것도 또 그것 나름대로 불안하네.. 
Posted by 구차니
개소리 왈왈/자전거2014. 1. 11. 20:08
아 춰춰춰
아.. 먼가 잊은게 있었나 했떠니..
돌아올때 안찍었구나.. ㅠㅠ


'개소리 왈왈 > 자전거' 카테고리의 다른 글

3.1절 맞이 시즌 온 자전거 타기  (0) 2014.03.01
오늘의 지름 - 휴대용 토크렌찌  (0) 2014.02.28
2014 랜도너스 도전?  (2) 2013.12.23
바이크 쇼 2013  (6) 2013.11.29
금강 종주 완료  (0) 2013.11.23
Posted by 구차니