I = randn(100,100);
x = linspace(0,1);
y = linspace(0,1);

N = 49*3e5;
n_iter=20;
xi= rand(1,N)*0.99+0.005;
yi= rand(1,N)*0.99+0.005;
[xm,ym]=meshgrid(x,y);
tic;
for n=1:n_iter
	I_matlab = interp2(x,y,I,xi,yi,'linear');
end
t1 = toc;
fprintf('took %f seconds\n', t1);

%% gpu
tic;
xi_gpu=gpuArray(xi);
yi_gpu=gpuArray(yi);
x_gpu=gpuArray(x);
y_gpu=gpuArray(y);
I_gpu=gpuArray(I);
for n=1:n_iter
	res_gpu= interpn(x_gpu,y_gpu,I_gpu,xi_gpu,yi_gpu,'linear');
	%res_gpu=gather(res_gpu);
end
	%x,y,I.',xi,yi);
t2 = toc;
fprintf('took %f seconds\n', t2);

res_norm = norm(res_gpu(:)-I_matlab(:));
fprintf('res norm = %g\n', res_norm);
fprintf('speedup %f x\n', t1/t2);