STRING(TOLOWER ${build_name} _build_lowercase)
SET(_target ${test_basename}.${_build_lowercase})
LIST(APPEND ALL_TESTS "${_target}")
- ADD_EXECUTABLE(${_target} EXCLUDE_FROM_ALL ${test_basename}.cc)
+ IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${test_basename}.cc")
+ ADD_EXECUTABLE(${_target} EXCLUDE_FROM_ALL ${test_basename}.cc)
+ ELSE()
+ ADD_EXECUTABLE(${_target} EXCLUDE_FROM_ALL ${test_basename}.cu)
+ ENDIF()
DEAL_II_INSOURCE_SETUP_TARGET(${_target} ${build_name})
IF("${mpi_run}" STREQUAL "")
make_quicktest("assimp" ${_mybuild} "")
ENDIF()
+# Test CUDA
+IF (DEAL_II_WITH_CUDA)
+ make_quicktest("cuda" ${_mybuild} "")
+ENDIF()
+
# A custom test target:
ADD_CUSTOM_TARGET(test
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+#include <deal.II/base/exceptions.h>
+#include <array>
+#include <iostream>
+#include <numeric>
+
+using namespace dealii;
+
+__global__ void double_value(double *x, double *y)
+{
+ y[threadIdx.x] = 2. * x[threadIdx.x];
+}
+
+int main()
+{
+ constexpr int n = 4;
+
+ std::array<double, n> host_x {};
+ std::iota(host_x.begin(), host_x.end(), 1);
+ std::array<double, n> host_y {};
+
+ // Copy input data to device.
+ double *device_x;
+ double *device_y;
+ cudaMalloc(&device_x, n * sizeof(double));
+ cudaMalloc(&device_y, n * sizeof(double));
+ cudaMemcpy(device_x, host_x.data(), n * sizeof(double),
+ cudaMemcpyHostToDevice);
+
+ // Launch the kernel.
+ double_value<<<1, n>>>(device_x, device_y);
+
+ // Copy output data to host.
+ cudaDeviceSynchronize();
+ cudaMemcpy(host_y.data(), device_y, n * sizeof(double),
+ cudaMemcpyDeviceToHost);
+
+ // Print the results and test
+ for (int i = 0; i < n; ++i)
+ {
+ std::cout << "y[" << i << "] = " << host_y[i] << "\n";
+ AssertThrow(std::abs(host_y[i]-2*host_x[i])<1.e-10, ExcInternalError());
+ }
+
+ cudaDeviceReset();
+ return 0;
+}