Commit edd4ab2d52c0226d4980644941ab4e215aff9ba3
1 parent
ef64ebad
Cleaned up more and comments, and added small debugging to cost.h for tests and clarity
Showing
2 changed files
with
15 additions
and
12 deletions
Show diff stats
stim/cuda/cost.h
... | ... | @@ -3,8 +3,9 @@ |
3 | 3 | #include <cuda_runtime.h> |
4 | 4 | #include <cublas_v2.h> |
5 | 5 | #include <stdio.h> |
6 | -#include "../visualization/colormap.h" | |
6 | +#include <stim/visualization/colormap.h> | |
7 | 7 | #include <sstream> |
8 | +#include <stim/math/mathvec.h> | |
8 | 9 | |
9 | 10 | |
10 | 11 | ///Cost function that works with the gl-spider class to find index of the item with min-cost. |
... | ... | @@ -125,17 +126,18 @@ void cleanUP(cudaGraphicsResource_t src) |
125 | 126 | ///@param DIM_Y, the number of samples in the template. |
126 | 127 | ///@inter temporary paramenter that tracks the number of times cost.h was called. |
127 | 128 | extern "C" |
128 | -int get_cost(cudaGraphicsResource_t src, int inter, int DIM_Y) | |
129 | +stim::vec<int> get_cost(cudaGraphicsResource_t src, int DIM_Y) | |
129 | 130 | { |
130 | 131 | float output[DIM_Y]; |
132 | + stim::vec<int> ret(0, 0); | |
131 | 133 | float mini = 10000000000000000.0; |
132 | 134 | int idx; |
133 | 135 | stringstream name; //for debugging |
136 | + name << "Test.bmp"; | |
134 | 137 | initArray(src, DIM_Y*10); |
135 | 138 | dim3 grid(20, DIM_Y*10); |
136 | 139 | dim3 block(1, 1); |
137 | 140 | get_diff <<< grid, block >>> (result); |
138 | - name << "temp_diff_" << inter << ".bmp"; | |
139 | 141 | stim::gpu2image<float>(result, name.str(), 20,DIM_Y*10,0,1); |
140 | 142 | for (int i = 0; i < DIM_Y; i++){ |
141 | 143 | output[i] = get_sum(result+(20*10*i)); |
... | ... | @@ -144,10 +146,12 @@ int get_cost(cudaGraphicsResource_t src, int inter, int DIM_Y) |
144 | 146 | idx = i; |
145 | 147 | } |
146 | 148 | } |
147 | - name.clear(); | |
148 | - name << "sample_" << inter << "_" << idx << ".bmp"; | |
149 | + | |
150 | +// name.clear(); | |
151 | +// name << "sample_" << inter << "_" << idx << ".bmp"; | |
149 | 152 | output[idx] = get_sum(result+(20*10*idx)); |
150 | - stim::gpu2image<float>(v_dif, name.str(), 20,10,0,1); | |
153 | +// stim::gpu2image<float>(v_dif, name.str(), 20,10,0,1); | |
151 | 154 | cleanUP(src); |
152 | - return idx; | |
155 | + ret[0] = idx; ret[1] = (int) output[idx]; | |
156 | + return ret; | |
153 | 157 | } | ... | ... |
stim/gl/gl_spider.h
... | ... | @@ -53,7 +53,6 @@ class gl_spider |
53 | 53 | GLuint dList; |
54 | 54 | GLuint fboID; |
55 | 55 | GLuint texbufferID; |
56 | - int iter; //temporary for testing | |
57 | 56 | int numSamples; |
58 | 57 | float stepsize = 3.0; |
59 | 58 | |
... | ... | @@ -491,10 +490,11 @@ class gl_spider |
491 | 490 | getCost() |
492 | 491 | { |
493 | 492 | createResource(); |
494 | - int cost = get_cost(resource, iter, numSamples); | |
493 | + stim::vec<int> cost = get_cost(resource, numSamples); | |
495 | 494 | destroyResource(); |
496 | - iter++; | |
497 | - return cost; | |
495 | + if (cost[1] >= 80) | |
496 | + exit(0); | |
497 | + return cost[0]; | |
498 | 498 | } |
499 | 499 | |
500 | 500 | public: |
... | ... | @@ -555,7 +555,6 @@ class gl_spider |
555 | 555 | attachSpider(GLuint id) |
556 | 556 | { |
557 | 557 | texID = id; |
558 | - iter = 0; ///for debugging purposes | |
559 | 558 | GenerateFBO(20, numSamples*10); |
560 | 559 | setDims(0.6, 0.6, 1.0); |
561 | 560 | setSize(512.0, 512.0, 426.0); | ... | ... |