view src/parallel_execution/examples/CUDAtwice.cu @ 329:8592a1d161b7 examples_directory

Move CUDAtwice example to examples directory
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Tue, 18 Apr 2017 06:04:22 +0900
parents src/parallel_execution/CUDAtwice.cu@7dd5a7d52a67
children
line wrap: on
line source

extern "C" {

#include <stdio.h>

//    __global__ void twice(struct LoopCounter* loopCounter, int prefix ,int* array) {
//         int index = blockIdx.x * blockDim.x + threadIdx.x;
//         printf("array %p, blockIdx.x = %d, blockDim.x = %d, threadIdx.x = %d\n");
//         int i = 0;
//         while (i < prefix) {
//              array[i+index*prefix] = array[i+index*prefix]*2;
//         }
//    }

    struct LoopCounter {
        int i;
    } LoopCounter;

    __global__ void twice(struct LoopCounter* loopCounter, int index, int prefix, int* array) {
         printf("array %p, index = %d, prefix = %d loopCounter->i %d\n",array,index,prefix,loopCounter->i);
C_twice:
        int i = loopCounter->i;
        if (i < prefix) {
            array[i+index*prefix] = array[i+index*prefix]*2;
            loopCounter->i++;

            goto C_twice;
        }

        loopCounter->i = 0;
    }


}