Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First cut at adding a CUDA application

  • Loading branch information...
commit b7e4f18d3e7ff0176eb8314326d7c555a2032eac 1 parent 6fa6174
@broxtronix broxtronix authored
View
13 config/cuda.mak
@@ -0,0 +1,13 @@
+# Makerules.
+
+SUFFIXES += .cu.o .cu.lo .cu
+
+.cu.o:
+ nvcc $< -c $@
+
+.cu.lo:
+ nvcc $< -c $@
+
+.cu:
+ nvcc $< -o $@
+
View
1  config/rules.mak
@@ -33,3 +33,4 @@ CXXTEST_ARGS = --error-printer
$(CXXTEST_GEN) $(CXXTEST_ARGS) -o $@ $<
include $(top_srcdir)/config/autotroll.mak
+include $(top_srcdir)/config/cuda.mak
View
4 configure.ac
@@ -282,6 +282,8 @@ AX_PKG(VW_CAMERA, [BOOST], [-lvwCamera], [vw/Camera/CAHVModel.h])
AX_PKG(VW_CARTOGRAPHY, [BOOST], [-lvwCartography], [vw/Cartography/GeoReference.h])
AX_PKG(VW_INTEREST_POINT, [BOOST], [-lvwInterestPoint])
+AX_PKG(CUDA, [], [-lcuda], [cuda.h])
+
AX_PKG(OPENSCENEGRAPH, [], [-losg -losgDB -lOpenThreads -losgViewer -losgText -losgGA -losgFX -losgTerrain -losgUtil], [osg/ref_ptr])
AX_PKG(MBA10, [BOOST], [-lMBA_1.0_gpl_opt], [MBA.h])
@@ -360,6 +362,7 @@ AX_APP(RMAXADJUST, [src], no, [BOOST BOOST_PROGRAM_OPTIONS BOOST_FILESYSTEM VW V
AX_APP(BUNDLEVIS, [src], no, [BOOST BOOST_PROGRAM_OPTIONS OPENSCENEGRAPH VW VW_CAMERA])
AX_APP(ISISADJUST, [src], yes, [BOOST BOOST_PROGRAM_OPTIONS BOOST_FILESYSTEM VW VW_CAMERA VW_STEREO VW_CARTOGRAPHY VW_INTEREST_POINT LAPACK ISIS])
AX_APP(RESULTS, [src], yes, [BOOST BOOST_PROGRAM_OPTIONS BOOST_FILESYSTEM VW VW_CAMERA VW_STEREO VW_CARTOGRAPHY VW_INTEREST_POINT LAPACK ISIS])
+AX_APP(CUDATEST, [src], no, [VW CUDA])
# These are here (instead of inside the APP macro where they belong)
# for backwards compatability with older versions of automake.
@@ -378,6 +381,7 @@ AM_CONDITIONAL(MAKE_APP_RMAX2CAHVOR, [test "$MAKE_APP_RMAX2CAHVOR" = "yes"])
AM_CONDITIONAL(MAKE_APP_RMAXADJUST, [test "$MAKE_APP_RMAXADJUST" = "yes"])
AM_CONDITIONAL(MAKE_APP_BUNDLEVIS, [test "$MAKE_APP_BUNDLEVIS" = "yes"])
AM_CONDITIONAL(MAKE_APP_RESULTS, [test "$MAKE_APP_RESULTS" = "yes"])
+AM_CONDITIONAL(MAKE_APP_CUDATEST, [test "$MAKE_APP_CUDATEST" = "yes"])
##################################################
# final processing
##################################################
View
6 src/Makefile.am
@@ -174,6 +174,12 @@ if MAKE_APP_RESULTS
results_LDFLAGS = $(APP_RESULTS_LIBS)
endif
+if MAKE_APP_CUDATEST
+ bin_PROGRAMS += cuda_test
+ CUDATEST_SOURCES = cuda_test.cu
+ CUDATEST_LDFLAGS = $(APP_CUDATEST_LIBS) $(ASP_LDFLAGS) -lcuda
+endif
+
AM_CPPFLAGS = @ASP_CPPFLAGS@
AM_LDFLAGS = @ASP_LDFLAGS@
View
55 src/cuda_test.cu
@@ -0,0 +1,55 @@
+// VW
+#include <vw/vw.h>
+
+// includes, system
+#include <iostream>
+
+// includes, project
+#include <cuda.h>
+
+/* --------------------------- target code ------------------------------*/
+#define ACOS_THREAD_CNT 128
+#define N 128
+
+struct acosParams {
+ float *arg;
+ float *res;
+ int n;
+};
+
+__global__ void acos_main (struct acosParams parms)
+{
+ int i;
+ for (i = threadIdx.x; i < parms.n; i += ACOS_THREAD_CNT) {
+ parms.res[i] = acosf(parms.arg[i]);
+ }
+}
+
+/* --------------------------- host code ------------------------------*/
+
+int main (int argc, char *argv[])
+{
+ cudaError_t cudaStat;
+ float* acosRes = 0;
+ float* acosArg = 0;
+ float* arg[N];
+ float* res[N];
+ struct acosParams funcParams;
+
+ // ... fill arguments array ‘arg’ ....
+
+ cout << "Hello, world3.\n";
+ cudaStat = cudaMalloc ((void **)&acosArg, N * sizeof(acosArg[0]));
+ cudaStat = cudaMemcpy (acosArg, arg, N * sizeof(arg[0]), cudaMemcpyHostToDevice);
+
+ funcParams.res = acosRes;
+ funcParams.arg = acosArg;
+ funcParams.n = N;
+
+ acos_main<<<1,ACOS_THREAD_CNT>>>(funcParams);
+
+ cudaStat = cudaMemcpy (res, acosRes, N * sizeof(res[0]), cudaMemcpyDeviceToHost);
+
+ // ... process result array ‘res’ ....
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.