Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. #include "definitionsInternal.h"
  2. #include "supportCode.h"
  3.  
  4. extern "C" __global__ void preNeuronResetKernel() {
  5. unsigned int id = 32 * blockIdx.x + threadIdx.x;
  6. if(id == 0) {
  7. dd_glbSpkCntE[0] = 0;
  8. }
  9. else if(id == 1) {
  10. dd_glbSpkCntI[0] = 0;
  11. }
  12. }
  13. extern "C" __global__ void updateNeuronsKernel(float t)
  14. {
  15. const unsigned int id = 128 * blockIdx.x + threadIdx.x;
  16. __shared__ volatile unsigned int shSpk[128];
  17. __shared__ volatile unsigned int shPosSpk;
  18. __shared__ volatile unsigned int shSpkCount;
  19. if (threadIdx.x == 0); {
  20. shSpkCount = 0;
  21. }
  22.  
  23. __syncthreads();
  24. // E
  25. if(id < 3200) {
  26.  
  27. if(id < 3200) {
  28. scalar lV = dd_VE[id];
  29. scalar lRefracTime = dd_RefracTimeE[id];
  30.  
  31. float Isyn = 0;
  32. // pull inSyn values in a coalesced access
  33. float linSynIE = dd_inSynIE[id];
  34. Isyn += (9.51625819640404824e-01f) * linSynIE;
  35. // pull inSyn values in a coalesced access
  36. float linSynEE = dd_inSynEE[id];
  37. Isyn += (9.06346234610090895e-01f) * linSynEE;
  38. // test whether spike condition was fulfilled previously
  39. const bool oldSpike= (lRefracTime <= 0.0f && lV >= (-5.00000000000000000e+01f));
  40. // calculate membrane potential
  41. if (lRefracTime <= 0.0f)
  42. {
  43. scalar alpha = ((Isyn + (0.00000000000000000e+00f)) * (2.00000000000000000e+01f)) + (-4.90000000000000000e+01f);
  44. lV = alpha - ((9.51229424500714016e-01f) * (alpha - lV));
  45. }
  46. else
  47. {
  48. lRefracTime -= DT;
  49. }
  50.  
  51. // test for and register a true spike
  52. if ((lRefracTime <= 0.0f && lV >= (-5.00000000000000000e+01f)) && !(oldSpike)) {
  53. const unsigned int spkIdx = atomicAdd((unsigned int *) &shSpkCount, 1);
  54. shSpk[spkIdx] = id;
  55. // spike reset code
  56. lV = (-6.00000000000000000e+01f);
  57. lRefracTime = (5.00000000000000000e+00f);
  58.  
  59. }
  60. dd_VE[id] = lV;
  61. dd_RefracTimeE[id] = lRefracTime;
  62. // the post-synaptic dynamics
  63. linSynIE*=(9.04837418035959518e-01f);
  64. dd_inSynIE[id] = linSynIE;
  65. // the post-synaptic dynamics
  66. linSynEE*=(8.18730753077981821e-01f);
  67. dd_inSynEE[id] = linSynEE;
  68. }
  69. __syncthreads();
  70. if (threadIdx.x == 0) {
  71. if (shSpkCount > 0) {
  72. shPosSpk = atomicAdd((unsigned int *) &dd_glbSpkCntE[0], shSpkCount);
  73. }
  74. }
  75. __syncthreads();
  76. if (threadIdx.x < shSpkCount) {
  77. const unsigned int n = shSpk[threadIdx.x];
  78. dd_glbSpkE[shPosSpk + threadIdx.x] = n;
  79. }
  80. }
  81.  
  82. // I
  83. if(id >= 3200 && id < 4096) {
  84. const unsigned int lid = id - 3200;
  85.  
  86. if(lid < 800) {
  87. scalar lV = dd_VI[lid];
  88. scalar lRefracTime = dd_RefracTimeI[lid];
  89.  
  90. float Isyn = 0;
  91. // pull inSyn values in a coalesced access
  92. float linSynII = dd_inSynII[lid];
  93. Isyn += (9.51625819640404824e-01f) * linSynII;
  94. // pull inSyn values in a coalesced access
  95. float linSynEI = dd_inSynEI[lid];
  96. Isyn += (9.06346234610090895e-01f) * linSynEI;
  97. // test whether spike condition was fulfilled previously
  98. const bool oldSpike= (lRefracTime <= 0.0f && lV >= (-5.00000000000000000e+01f));
  99. // calculate membrane potential
  100. if (lRefracTime <= 0.0f)
  101. {
  102. scalar alpha = ((Isyn + (0.00000000000000000e+00f)) * (2.00000000000000000e+01f)) + (-4.90000000000000000e+01f);
  103. lV = alpha - ((9.51229424500714016e-01f) * (alpha - lV));
  104. }
  105. else
  106. {
  107. lRefracTime -= DT;
  108. }
  109.  
  110. // test for and register a true spike
  111. if ((lRefracTime <= 0.0f && lV >= (-5.00000000000000000e+01f)) && !(oldSpike)) {
  112. const unsigned int spkIdx = atomicAdd((unsigned int *) &shSpkCount, 1);
  113. shSpk[spkIdx] = lid;
  114. // spike reset code
  115. lV = (-6.00000000000000000e+01f);
  116. lRefracTime = (5.00000000000000000e+00f);
  117.  
  118. }
  119. dd_VI[lid] = lV;
  120. dd_RefracTimeI[lid] = lRefracTime;
  121. // the post-synaptic dynamics
  122. linSynII*=(9.04837418035959518e-01f);
  123. dd_inSynII[lid] = linSynII;
  124. // the post-synaptic dynamics
  125. linSynEI*=(8.18730753077981821e-01f);
  126. dd_inSynEI[lid] = linSynEI;
  127. }
  128. __syncthreads();
  129. if (threadIdx.x == 0) {
  130. if (shSpkCount > 0) {
  131. shPosSpk = atomicAdd((unsigned int *) &dd_glbSpkCntI[0], shSpkCount);
  132. }
  133. }
  134. __syncthreads();
  135. if (threadIdx.x < shSpkCount) {
  136. const unsigned int n = shSpk[threadIdx.x];
  137. dd_glbSpkI[shPosSpk + threadIdx.x] = n;
  138. }
  139. }
  140.  
  141. }
  142. void updateNeurons(float) {
  143. {
  144. const dim3 threads(32, 1);
  145. const dim3 grid(1, 1);
  146. preNeuronResetKernel<<<grid, threads>>>();
  147. }
  148. {
  149. cudaEventRecord(neuronUpdateStart);
  150. const dim3 threads(128, 1);
  151. const dim3 grid(32, 1);
  152. updateNeuronsKernel<<<grid, threads>>>(t);
  153. cudaEventRecord(neuronUpdateStop);
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement