Skip to content

Instantly share code, notes, and snippets.

@U-MA
U-MA / sample_merge.vfl
Last active April 18, 2020 04:59
VEX でカスタム COP 作成
#pragma opname sample_merge
#pragma oplabel "SampleMerge"
#pragma opmaxinputs 4
#pragma inputlabel 1 "R"
#pragma inputlabel 2 "G"
#pragma inputlabel 3 "B"
#pragma inputlabel 4 "A"
#pragma label useChannelOfR "Use channel of R"
#pragma choice useChannelOfR "0" "R"
#pragma choice useChannelOfR "1" "G"
@U-MA
U-MA / exercise0603.cpp
Last active December 30, 2015 03:39
CUDA プログラミング実践講座 6.8演習 6.3
/* CUDA プログラミング実践講座 演習6.3の解答 */
/* 図6.2の改良版 */
__global__ void reduction_kernel0602(float *array)
{
extern __shared__ float partialSum[];
unsigned int tid = threadIdx.x;
unsigned int bid = blockIdx.x;
unsigned int arrayIdx = bid * blockDim.x + (2*tid); /* (2) */
/* 図6.2の改良
* テキストと同様にグローバルメモリと共有メモリの間のコピーは除いている
*/
__global__ void reduction_kernel(float *array)
{
extern __shared__ float partialSum[];
unsigned int t = 2*threadIdx.x;
for (unsigned int stride = 1; stride <= blockDim.x; stride *= 2)
/* 図6.4の改良
* テキストと同様にグローバルメモリとshared memoryの間のコピーは省略
*/
__global__ reduction_kernel(float *array)
{
extern __shared__ float patrialSum[];
unsigned int t = threadIdx.x;
for (unsigned int stride = blockDim.x; stride > 0; stride >>= 1)
__global__ void kernel(...)
{
__shared__ int candidates[32], candidateSize;
int customer = threadIdx.x;
candidateSize = 0;
if (customer < 32 && !isVisited(customer))
{
int old = atomicAdd(&candidateSize, 1);
candidate[old] = customer;
__global__ void kernel(...)
{
__shared__ int candidates[32], candidateSize;
int customer = threadIdx.x;
candidateSize = 0;
if (customer < 32 && !isVisited(customer))
{
atomicAdd(&candidate[candidateSize], customer);
atomicAdd(&candidateSize, 1);
@U-MA
U-MA / gist:7546810
Last active December 28, 2015 18:59
typedef struct distnce
{
int *cost;
} distance;
typedef struct problem
{
distance dist;
} problem;
@U-MA
U-MA / va_list_sample.cpp
Last active October 8, 2015 13:07
va_listのサンプル
#include <cstdio>
#include <cstdarg>
template<typename T>
T sumN(unsigned int n, ...)
{
va_list vl;
va_start(vl, n);
T sum = 0;
@U-MA
U-MA / count_if.vim
Created September 5, 2015 12:31
条件に一致する要素の個数を返す関数
function! s:count_if(list, string) abort
let copy = deepcopy(a:list)
call filter(copy, a:string)
return len(copy)
endfunction
function! s:foo(second) abort
let l:start = reltime()
while str2float(reltimestr(reltime(l:start))) < float(a:second)
execute 'normal! r '
endwhile
endfunction
tabnew Sample
call setline(1, 'Please any keys for 2 seconds.')