26 #include <cuda_runtime_api.h> 29 #include "cuda_gpu_geo_shift_transformer.cu" 57 this->device = device;
58 this->stream = stream;
81 init(gpu, x, y, n, device, stream);
86 template<
typename T_IN>
89 checkRestrictions(output, input);
90 if (output.
xdim == 0) {
93 if (shiftX == 0 && shiftY == 0) {
102 imgs->copyToGpu(tmp.
data);
104 imgs->fftStream(*ffts, fftHandle, *stream,
false, mask);
106 imgs->fft(*ffts, fftHandle);
110 dim3 dimGrid(ceil(ffts->Xdim / (T) dimBlock.x), ceil(ffts->Ydim / (T) dimBlock.y));
113 shiftFFT2D<true><<<dimGrid, dimBlock, 0, *(cudaStream_t*)stream->ptr>>>(
114 (float2*)ffts->d_data, ffts->Ndim, ffts->Xdim, imgs->Xdim,
115 imgs->Ydim, shiftX, shiftY);
117 shiftFFT2D<true><<<dimGrid, dimBlock>>>((float2*)ffts->d_data,
118 ffts->Ndim, ffts->Xdim, imgs->Xdim, imgs->Ydim, shiftX, shiftY);
123 ffts->ifftStream(*imgs, ifftHandle, *stream,
false, mask);
125 ffts->ifft(*imgs, ifftHandle);
127 imgs->copyToCpu(output.
data);
139 for (
int y = 10;
y < 15; ++
y) {
140 for (
int x = 10;
x < 15; ++
x) {
141 int indexIn = (
y * input.
xdim) +
x;
142 int indexExp = ((
y + offsetY) * input.
xdim) + (
x + offsetX);
143 input.
data[indexIn] = 10;
144 expected.
data[indexExp] = 10;
151 tr.
applyShift(resGpu, input, offsetX, offsetY);
154 for (
int y = 0;
y < expected.
ydim; ++
y) {
155 for (
int x = 0;
x < expected.
xdim; ++
x) {
161 if (diff > threshold && diff > 0.001) {
163 printf(
"%d gpu %.4f cpu %.4f (%f > %f)\n", index, gpu, cpu, diff, threshold);
170 img.
write(
"expected.vol");
172 img.
write(
"resGpu.vol");
174 printf(
"\n SHIFT %s\n", error ?
"FAILED" :
"OK");
178 template<
typename T_IN>
182 throw std::logic_error(
"Shift transformer: Not initialized");
185 throw std::invalid_argument(
"Shift transformer: Input is empty");
187 if ((imgs->Xdim != input.
xdim) || (imgs->Ydim != input.
ydim)
188 || (imgs->Zdim != input.
zdim) || (imgs->Ndim != input.
ndim))
189 throw std::logic_error(
190 "Shift transformer: Initialized for different sizes");
195 throw std::logic_error(
196 "Shift transformer: Input/output dimensions do not match");
199 throw std::invalid_argument(
200 "Shift transformer: The input array cannot be the same as the output array");
void resizeNoCopy(const MultidimArray< T1 > &v)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
void abs(Image< double > &op)
void createPlanFFTStream(int Xdim, int Ydim, int Ndim, int Zdim, bool forward, cufftHandle *plan, myStreamHandle &myStream)
void threshold(double *phi, unsigned long nvox, double limit)
void max(Image< double > &op1, const Image< double > &op2)
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
void createPlanFFT(int Xdim, int Ydim, int Ndim, int Zdim, bool forward, cufftHandle *plan)