You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.7 KiB
72 lines
1.7 KiB
''' |
|
''' |
|
|
|
import pycuda.driver as cuda |
|
import pycuda.autoinit |
|
|
|
from pycuda.compiler import SourceModule |
|
|
|
|
|
class SignalCalculator(): |
|
''' |
|
''' |
|
|
|
|
|
def __init__(self): |
|
''' |
|
''' |
|
self.generators = [] |
|
|
|
def add_signal_generator(self, gen): |
|
self.generators.append(gen) |
|
|
|
def make_cuda_kernel(self): |
|
src = """ |
|
#include <curand_kernel.h> |
|
|
|
const int nstates = %(NGENERATORS)s; |
|
__device__ curandState_t* states[nstates]; |
|
|
|
__global__ void initkernel(int seed) |
|
{ |
|
int tidx = threadIdx.x + blockIdx.x * blockDim.x; |
|
|
|
if (tidx < nstates) { |
|
curandState_t* s = new curandState_t; |
|
if (s != 0) { |
|
curand_init(seed, tidx, 0, s); |
|
} |
|
|
|
states[tidx] = s; |
|
} |
|
} |
|
|
|
__global__ void calc_signal(float* open, float* high, float* low, float* close, size_t points, int8_t* signals, char* sig_names, float* scratch) |
|
{ |
|
int tidx = threadIdx.x + blockIdx.x * blockDim.x; |
|
curandState_t s = *states[tidx]; |
|
int signals = 5 * curand_uniform(&s); |
|
float* tScratch = &scratch[tidx * points]; |
|
int8_t* tSignals = &signals[tidx * points]; |
|
char* tSigName = &signames[tidx * 256]; |
|
|
|
for(int i = 0; i < signals; i++) |
|
{ |
|
int sigtype = curand_uniform(&s); |
|
switch(sigtype) |
|
{ |
|
""" |
|
|
|
i = 0 |
|
for gen in self.generators: |
|
src += gen.make_signal_kernel(i) |
|
i += 1 |
|
|
|
src += """ |
|
} |
|
} |
|
} |
|
""" |
|
|
|
|
|
|