old_contents:
#include "tst_fptrs.h"
#include "user_f.h"

#include <stdio.h>

void assign_cuda_ptr(fc2d_cuda_t* h_f, fc2d_cuda_t f)
{
    cudaError_t ce = cudaMemcpyFromSymbol(h_f, f, sizeof(fc2d_cuda_t));
    if(ce != cudaSuccess)
    {
        printf("ERROR: %s\n",cudaGetErrorString(ce));
        exit(0);
    }
    else
    {
        printf("Success!\n");
    }
}

__global__ void kernel(fc2d_cuda_t f,float x, float *y)
{
    *y = f(x);
    return;
}

int main()
{
    float x;
    float y, *y_dev;
    fc2d_assign_cuda_ptr_t f_assign_user;

    fc2d_cuda_t h_f;

    /* User definitions */
    x = 5;
    f_assign_user = assign_cuda_ptr2;  /* Function pointer stored in a v-table */

    /* Code */
    f_assign_user(&h_f);

    cudaMalloc((void**) &y_dev, sizeof(float));

    kernel<<<1,1>>>(h_f,x,y_dev);

    cudaMemcpy(&y, y_dev, sizeof(float), cudaMemcpyDeviceToHost);

    printf("x = %f; y = %f\n",x,y);

    return 0;
}

new_contents:
#include "tst_fptrs.h"
#include "user_f.h"

#include <stdio.h>

__global__ void kernel(fc2d_cuda_t f,float x, float *y)
{
    *y = f(x);
    return;
}

int main()
{
    float x;
    float y, *y_dev;
    fc2d_assign_cuda_ptr_t f_assign_user;

    fc2d_cuda_t h_f;

    /* User definitions */
    x = 5;
    f_assign_user = assign_cuda_ptr2;  /* Function pointer stored in a v-table */

    /* Code */
    f_assign_user(&h_f);

    cudaMalloc((void**) &y_dev, sizeof(float));

    kernel<<<1,1>>>(h_f,x,y_dev);

    cudaMemcpy(&y, y_dev, sizeof(float), cudaMemcpyDeviceToHost);

    printf("x = %f; y = %f\n",x,y);

    return 0;
}

subject: Update cuda snippet illustrating Cuda function pointers


old_contents:
#include <iostream>
#include <string>
#include <gunrock/cuda/device_properties.hxx>

int main(int argc, char** argv) {
    using namespace std;
    using namespace gunrock::cuda;
    using namespace gunrock::cuda::properties;

    int cc_ver = (argc > 1) ? stoi(argv[1]) : 30;
    compute_capability_t cc = make_compute_capability(cc_ver);
    const char *arch = arch_name(cc);

    cout << "Compute Capability Version Major: " << cc.major << endl;
    cout << "Compute Capability Version Minor: " << cc.minor << endl;

    if (arch != nullptr)
        cout << "Compute Capability Architecture: " << arch << endl;

    cout << endl;
    cout << "cta_max_threads:           " << cta_max_threads() << endl;
    cout << "warp_max_threads:          " << warp_max_threads() << endl;
    cout << "sm_max_ctas:               " << sm_max_ctas(cc) << endl;
    cout << "sm_max_threads:            " << sm_max_threads(cc) << endl;
    cout << "sm_registers:              " << sm_registers(cc) << endl;
    cout << "sm_max_smem_bytes:         " << sm_max_smem_bytes(cc) << endl;
    cout << "shared_memory_banks:       " << shared_memory_banks() << endl;
    cout << "shared_memory_bank_stride: " << shared_memory_bank_stride() << endl;
}

subject: Change indentation to 2 spaces

message: Change indentation to 2 spaces


old_contents:
#include <unittest/unittest.h>
#include <thrust/system/cuda/memory.h>

template<typename T1, typename T2>
bool is_same(const T1 &, const T2 &)
{
  return false;
}

template<typename T>
bool is_same(const T &, const T &)
{
  return true;
}

void TestSelectSystemCudaToCpp()
{
  using thrust::system::detail::generic::select_system;

  // select_system(cuda::tag, cpp::tag) should return cuda_to_cpp
  bool is_cuda_to_cpp = is_same(thrust::system::cuda::detail::cuda_to_cpp(), select_system(thrust::cuda::tag(), thrust::cpp::tag()));
  ASSERT_EQUAL(true, is_cuda_to_cpp);
}
DECLARE_UNITTEST(TestSelectSystemCudaToCpp);

new_contents:
#include <unittest/unittest.h>
#include <thrust/system/cuda/memory.h>

template<typename T1, typename T2>
bool is_same(const T1 &, const T2 &)
{
  return false;
}

template<typename T>
bool is_same(const T &, const T &)
{
  return true;
}

void TestSelectSystemCudaToCpp()
{
  using thrust::system::detail::generic::select_system;

  // select_system(cuda::tag, thrust::host_system_tag) should return cuda_to_cpp
  bool is_cuda_to_cpp = is_same(thrust::system::cuda::detail::cuda_to_cpp(), select_system(thrust::cuda::tag(), thrust::host_system_tag()));
  ASSERT_EQUAL(true, is_cuda_to_cpp);
}
DECLARE_UNITTEST(TestSelectSystemCudaToCpp);

subject: Test host_system_tag rather than cpp::tag


old_contents:
#include <agency/cuda/execution_policy.hpp>
#include <cstdio>

struct kernel
{
  __device__
  void operator()(agency::parallel_group<agency::cuda::concurrent_agent>& self)
  {
    printf("hello from {%d, %d}\n", (int)self.outer().index(), (int)self.inner().index());
  }
};

auto grid(size_t num_blocks, size_t num_threads)
  -> decltype(
       agency::cuda::par(num_blocks, agency::cuda::con(num_threads))
     )
{
  return agency::cuda::par(num_blocks, agency::cuda::con(num_threads));
}

int main()
{
  bulk_invoke(grid(2,32), kernel());

  return 0;
}

new_contents:
#include <agency/cuda/execution_policy.hpp>
#include <cstdio>

struct kernel
{
  __device__
  void operator()(agency::parallel_group<agency::cuda::concurrent_agent>& self)
  {
    printf("hello from {%d, %d}\n", (int)self.outer().index(), (int)self.inner().index());
  }

  __device__
  void operator()(agency::parallel_group_2d<agency::cuda::concurrent_agent_2d>& self)
  {
  }
};

auto grid(size_t num_blocks, size_t num_threads)
  -> decltype(
       agency::cuda::par(num_blocks, agency::cuda::con(num_threads))
     )
{
  return agency::cuda::par(num_blocks, agency::cuda::con(num_threads));
}

//using parallel_execution_policy_2d = agency::cuda::detail::basic_execution_policy<agency::cuda::parallel_agent_2d, agency::cuda::parallel_executor>;
//const parallel_execution_policy_2d par_2d{};
//
//using concurrent_execution_policy_2d = agency::cuda::detail::basic_execution_policy<agency::cuda::concurrent_agent_2d, agency::cuda::block_executor>;
//const concurrent_execution_policy_2d con_2d{};
//
//// XXX eliminate the need for these specializations
//namespace agency
//{
//
//template<>
//struct is_execution_policy<parallel_execution_policy_2d> : std::true_type {};
//
//template<>
//struct is_execution_policy<concurrent_execution_policy_2d> : std::true_type {};
//
//}
//
//
//auto grid(agency::size2 num_blocks, agency::size2 num_threads)
//  -> decltype(
//       par_2d(num_blocks, con_2d(num_threads))
//     )
//{
//  return par_2d(num_blocks, con_2d(num_threads));
//}

int main()
{
  bulk_invoke(grid(2,32), kernel());

  // XXX this takes too long to compile
  //agency::cuda::bulk_invoke(grid({1,2}, {1,32}), kernel());

  return 0;
}

subject: Implement 2-dimensional grids, but leave commented out

repos: egaburov/agency,egaburov/agency


old_contents:
#include "grid_gpu.cuh"
#include "halide_buf.h"

extern "C"
int nvGridder(const double _scale, const int32_t _grid_size, buffer_t *_vis_buffer, buffer_t *_gcf_buffer, buffer_t *_uvg_buffer){
  gridGPUc( _scale
          , reinterpret_cast<CmplxType*>(_uvg_buffer->host)
          , reinterpret_cast<combined*>(_vis_buffer->host)
          , _vis_buffer->extent[1]
          , _grid_size
          , reinterpret_cast<CmplxType*>(_gcf_buffer->host)
          );
  return 0;
}

new_contents:
#include "grid_gpu.cuh"
#include "halide_buf.h"

extern "C"
int nvGridder(const double _scale, const int32_t _grid_size, buffer_t *_vis_buffer, buffer_t *_gcf_buffer, buffer_t *_uvg_buffer){
  // FIXME: make gridGPUx respect buffers locations, i.e.
  // to check if they already are on GPU and skip allocation and marshaling then
  gridGPUc( _scale
          , reinterpret_cast<CmplxType*>(_uvg_buffer->host)
          , reinterpret_cast<combined*>(_vis_buffer->host)
          , _vis_buffer->extent[1]
          , _grid_size
          , reinterpret_cast<CmplxType*>(_gcf_buffer->host)
          );
  _vis_buffer->dev = 0;
  _vis_buffer->host_dirty = false;
  _gcf_buffer->dev = 0;
  _gcf_buffer->host_dirty = false;

  _uvg_buffer->dev = 0;
  _uvg_buffer->host_dirty = false;
  _uvg_buffer->dev_dirty = false;

  return 0;
}

subject: Prepare NVidia gridder's Halide veneer to be used as drop-in replacement for the true Halide kernels.


old_contents:
/* rapt - RichieSam's Adventures in Path Tracing
 *
 * rapt is the legal property of Adrian Astley
 * Copyright Adrian Astley 2015
 */

#include "basic_path_tracer/path_trace.cuh"

uint32 WangHash(uint32 a) {
    a = (a ^ 61) ^ (a >> 16);
    a = a + (a << 3);
    a = a ^ (a >> 4);
    a = a * 0x27d4eb2d;
    a = a ^ (a >> 15);
    return a;
}

void PathTraceNextFrame(void *buffer, uint width, uint height, size_t pitch, DeviceCamera *camera, Scene::SceneObjects *sceneObjects, uint frameNumber) {
	cudaError_t error = cudaSuccess;

	dim3 Db = dim3(16, 16);   // block dimensions are fixed to be 256 threads
	dim3 Dg = dim3((width + Db.x - 1) / Db.x, (height + Db.y - 1) / Db.y);

	PathTraceKernel<<<Dg, Db>>>((unsigned char *)buffer, width, height, pitch, camera, sceneObjects, WangHash(frameNumber));

	error = cudaGetLastError();
	if (error != cudaSuccess) {
		//exit(error);
	}
}

new_contents:
/* rapt - RichieSam's Adventures in Path Tracing
 *
 * rapt is the legal property of Adrian Astley
 * Copyright Adrian Astley 2015
 */

#include "basic_path_tracer/path_trace.cuh"

uint32 WangHash(uint32 a) {
    a = (a ^ 61) ^ (a >> 16);
    a = a + (a << 3);
    a = a ^ (a >> 4);
    a = a * 0x27d4eb2d;
    a = a ^ (a >> 15);
    return a;
}

/**
 * Any code that uses CUDA semantics has to be a .cu/.cuh file. Instead of forcing
 * the entire project to be .cu/.cuh files, we can just wrap each cuda kernel launch
 * in a function. We forward declare the function in other parts of the project and
 * implement the functions here, in this .cu file.
 */
void PathTraceNextFrame(void *buffer, uint width, uint height, size_t pitch, DeviceCamera *camera, Scene::SceneObjects *sceneObjects, uint frameNumber) {
	cudaError_t error = cudaSuccess;

	dim3 Db = dim3(16, 16);   // block dimensions are fixed to be 256 threads
	dim3 Dg = dim3((width + Db.x - 1) / Db.x, (height + Db.y - 1) / Db.y);

	// The actual kernel launch call
	PathTraceKernel<<<Dg, Db>>>((unsigned char *)buffer, width, height, pitch, camera, sceneObjects, WangHash(frameNumber));

	error = cudaGetLastError();
	if (error != cudaSuccess) {
		//exit(error);
	}
}

message: BASIC_PATH_TRACER: Add comments to further explain the file arraignment of the kernel code

repos: RichieSams/rapt,RichieSams/rapt


old_contents:
/* originally from http://people.maths.ox.ac.uk/gilesm/ and modified */

//
// include files
//

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include <cutil_inline.h>

#include "prac5.h"

//
// kernel routine
//

__global__ void my_first_kernel(float *x)
{
  int tid = threadIdx.x + blockDim.x*blockIdx.x;

  x[tid] = threadIdx.x;
}

//
// CUDA routine to be called by main code
//

int prac5(int nblocks, int nthreads)
{
  float *h_x, *d_x;
  int   nsize, n;

  // allocate memory for arrays

  nsize = nblocks*nthreads ;

  h_x = (float *)malloc(nsize*sizeof(float));
  cudaMalloc((void **)&d_x, nsize*sizeof(float));

  // execute kernel

  my_first_kernel<<<nblocks,nthreads>>>(d_x);

  // copy back results and print them out

  cudaMemcpy(h_x,d_x,nsize*sizeof(float),cudaMemcpyDeviceToHost);

  for (n=0; n<nsize; n++) printf(" n,  x  =  %d  %f \n",n,h_x[n]);

  // free memory

  cudaFree(d_x);
  free(h_x);

  return 0;
}

new_contents:
/* originally from http://people.maths.ox.ac.uk/gilesm/ and modified */

//
// include files
//

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include <cuda.h>
#include "prac5.h"

//
// kernel routine
//

__global__ void my_first_kernel(float *x)
{
  int tid = threadIdx.x + blockDim.x*blockIdx.x;

  x[tid] = threadIdx.x;
}

//
// CUDA routine to be called by main code
//

int prac5(int nblocks, int nthreads)
{
  float *h_x, *d_x;
  int   nsize, n;

  // allocate memory for arrays

  nsize = nblocks*nthreads ;

  h_x = (float *)malloc(nsize*sizeof(float));
  cudaMalloc((void **)&d_x, nsize*sizeof(float));

  // execute kernel

  my_first_kernel<<<nblocks,nthreads>>>(d_x);

  // copy back results and print them out

  cudaMemcpy(h_x,d_x,nsize*sizeof(float),cudaMemcpyDeviceToHost);

  for (n=0; n<nsize; n++) printf(" n,  x  =  %d  %f \n",n,h_x[n]);

  // free memory

  cudaFree(d_x);
  free(h_x);

  return 0;
}

subject: Remove dependence on the CUDA SDK

message:
Remove dependence on the CUDA SDK

It turns out that this example does not really depend on the cuda SDK.  Thus
we remove the inclusion of the header file.  This is also nice because
CUDA 2.3 does not seem to have this header file.


old_contents:
// Copyright (c) 2009-2019 The Regents of the University of Michigan
// This file is part of the HOOMD-blue project, released under the BSD 3-Clause License.

// Maintainer: dnlebard

#include "hoomd/ParticleData.cuh"
#include "hoomd/HOOMDMath.h"
#include "hoomd/BondedGroupData.cuh"

/*! \file HarmonicDihedralForceGPU.cuh
    \brief Declares GPU kernel code for calculating the harmonic dihedral forces. Used by HarmonicDihedralForceComputeGPU.
*/

#ifndef __HARMONICDIHEDRALFORCEGPU_CUH__
#define __HARMONICDIHEDRALFORCEGPU_CUH__

//! Kernel driver that computes harmonic dihedral forces for HarmonicDihedralForceComputeGPU
cudaError_t gpu_compute_harmonic_dihedral_forces(Scalar4* d_force,
                                                 Scalar* d_virial,
                                                 const unsigned int virial_pitch,
                                                 const unsigned int N,
                                                 const Scalar4 *d_pos,
                                                 const BoxDim& box,
                                                 const group_storage<4> *tlist,
                                                 const unsigned int *dihedral_ABCD,
                                                 const unsigned int pitch,
                                                 const unsigned int *n_dihedrals_list,
                                                 Scalar5 *d_params,
                                                 unsigned int n_dihedral_types,
                                                 int block_size);

#endif

new_contents:
// Copyright (c) 2009-2019 The Regents of the University of Michigan
// This file is part of the HOOMD-blue project, released under the BSD 3-Clause License.

// Maintainer: dnlebard

#include "hoomd/ParticleData.cuh"
#include "hoomd/HOOMDMath.h"
#include "hoomd/BondedGroupData.cuh"

/*! \file HarmonicDihedralForceGPU.cuh
    \brief Declares GPU kernel code for calculating the harmonic dihedral forces. Used by HarmonicDihedralForceComputeGPU.
*/

#ifndef __HARMONICDIHEDRALFORCEGPU_CUH__
#define __HARMONICDIHEDRALFORCEGPU_CUH__

//! Kernel driver that computes harmonic dihedral forces for HarmonicDihedralForceComputeGPU
cudaError_t gpu_compute_harmonic_dihedral_forces(Scalar4* d_force,
                                                 Scalar* d_virial,
                                                 const unsigned int virial_pitch,
                                                 const unsigned int N,
                                                 const Scalar4 *d_pos,
                                                 const BoxDim& box,
                                                 const group_storage<4> *tlist,
                                                 const unsigned int *dihedral_ABCD,
                                                 const unsigned int pitch,
                                                 const unsigned int *n_dihedrals_list,
                                                 Scalar4 *d_params,
                                                 unsigned int n_dihedral_types,
                                                 int block_size);

#endif

subject: Revert datatype for scalar d_params

message: Revert datatype for scalar d_params


old_contents:
#include "grid_gpu.cuh"
#include "halide_buf.h"

extern "C"
int nvGridder(const double _scale, const int32_t _grid_size, buffer_t *_vis_buffer, buffer_t *_gcf_buffer, buffer_t *_uvg_buffer){
  // FIXME: make gridGPUx respect buffers locations, i.e.
  // to check if they already are on GPU and skip allocation and marshaling then
  gridGPUc( _scale
          , reinterpret_cast<CmplxType*>(_uvg_buffer->host)
          , reinterpret_cast<combined*>(_vis_buffer->host)
          , _vis_buffer->extent[1]
          , _grid_size
          , reinterpret_cast<CmplxType*>(_gcf_buffer->host)
          );
  _vis_buffer->dev = 0;
  _vis_buffer->host_dirty = false;
  _gcf_buffer->dev = 0;
  _gcf_buffer->host_dirty = false;

  _uvg_buffer->dev = 0;
  _uvg_buffer->host_dirty = false;
  _uvg_buffer->dev_dirty = false;

  return 0;
}

new_contents:
#include "grid_gpu.cuh"
#include "halide_buf.h"

extern "C"
EXPORT
int nvGridder(const double _scale, const int32_t _grid_size, buffer_t *_vis_buffer, buffer_t *_gcf_buffer, buffer_t *_uvg_buffer){
  #define visptr reinterpret_cast<combined*>(_vis_buffer->host)
  #define visnum _vis_buffer->extent[1]
  bin_sort5(visptr, visnum);
  // FIXME: make gridGPUx respect buffers locations, i.e.
  // to check if they already are on GPU and skip allocation and marshaling then
  gridGPUc( _scale
          , reinterpret_cast<CmplxType*>(_uvg_buffer->host)
          , visptr
          , visnum
          , _grid_size
          , reinterpret_cast<CmplxType*>(_gcf_buffer->host)
          );
  _vis_buffer->dev = 0;
  _vis_buffer->host_dirty = false;
  _gcf_buffer->dev = 0;
  _gcf_buffer->host_dirty = false;

  _uvg_buffer->dev = 0;
  _uvg_buffer->host_dirty = false;
  _uvg_buffer->dev_dirty = false;

  return 0;
}

subject: Add forgotten sort to Halide API.

message: Add forgotten sort to Halide API.


old_contents:
/***************************************************************************//**
* \mainpage cuIBM
*
*		A GPU-based Immersed Boundary Method
*
* \author Krishnan, A. (anush@bu.edu)
*/

/***************************************************************************//**
* \file cuIBM.cu
* \author Krishnan, A. (anush@bu.edu)
* \brief Main source-file of <B>cuIBM</B>
*/

#include "types.h"
#include "helpers.h"
#include "domain.h"
#include "io/io.h"
#include "solvers/NavierStokes/createSolver.h"

int main(int argc, char **argv)
{
	// initialize the computational domain
	domain dom_info;

	// initialize the parameters of the simulation
	parameterDB paramDB;

	// read input files
	io::readInputs(argc, argv, paramDB, dom_info);

	io::printSimulationInfo(paramDB, dom_info);

	// create and initialize the appropriate flow solver
	NavierStokesSolver<device_memory> *solver = createSolver<device_memory>(paramDB, dom_info);
	solver->initialise();

	io::printDeviceMemoryUsage("Initialisation complete");

	io::writeInfoFile(paramDB, dom_info);

	// time-step loop
	while (!solver->finished())
	{
		solver->stepTime();
		solver->writeData();
	}

	solver->shutDown();
}

new_contents:
/***************************************************************************//**
 * \mainpage cuIBM
 *
 *		A GPU-based Immersed Boundary Method
 *
 * \author Anush Krishnan (anush@bu.edu)
 */

/***************************************************************************//**
 * \file cuIBM.cu
 * \author Anush Krishnan (anush@bu.edu)
 * \brief Main source-file of <B>cuIBM</B>.
 */

#include "types.h"
#include "helpers.h"
#include "domain.h"
#include "io/io.h"
#include "solvers/NavierStokes/createSolver.h"

int main(int argc, char **argv)
{
	// initialize the computational domain
	domain dom_info;

	// initialize the parameters of the simulation
	parameterDB paramDB;

	// read input files
	io::readInputs(argc, argv, paramDB, dom_info);

	io::printSimulationInfo(paramDB, dom_info);

	// create and initialize the appropriate flow solver
	NavierStokesSolver<device_memory> *solver = createSolver<device_memory>(paramDB, dom_info);
	solver->initialise();

	io::printDeviceMemoryUsage("Initialisation complete");

	io::writeInfoFile(paramDB, dom_info);

	// time-step loop
	while (!solver->finished())
	{
		solver->stepTime();
		solver->writeData();
	}

	solver->shutDown();
}

subject: Update Doxygen documentation with conventions

license: mit


old_contents:
// Check that -fsanitize=foo doesn't get passed down to device-side
// compilation.
//
// REQUIRES: clang-driver
//
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 -fsanitize=address %s 2>&1 | \
// RUN:   FileCheck %s

// CHECK-NOT: error:
// CHECK-DAG: "-fcuda-is-device"
// CHECK-NOT: "-fsanitize=address"
// CHECK-DAG: "-triple" "x86_64--linux-gnu"
// CHECK: "-fsanitize=address"

new_contents:
// Check that -fsanitize=foo doesn't get passed down to device-side
// compilation.
//
// REQUIRES: clang-driver
//
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 -fsanitize=address %s 2>&1 | \
// RUN:   FileCheck %s

// CHECK-NOT: error: unsupported option '-fsanitize=address'
// CHECK-DAG: "-fcuda-is-device"
// CHECK-NOT: "-fsanitize=address"
// CHECK-DAG: "-triple" "x86_64--linux-gnu"
// CHECK: "-fsanitize=address"

subject: Fix faulty test from rL288448

message:
[CUDA] Fix faulty test from rL288448

Summary:
The test introduced by rL288448 is currently failing because
unimportant but unexpected errors appear as output from a test compile
line. This patch looks for a more specific error message, in order to
avoid false positives.

Reviewers: jlebar

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D27328

Switch to more specific error

git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@288453 91177308-0d34-0410-b5e6-96231b3b80d8


old_contents:
#include <agency/cuda/future.hpp>
#include <agency/future.hpp>
#include <iostream>
#include <cassert>

struct empty {};

int main()
{
  {
    // construction of future<void> from empty types

    using future_type1 = agency::cuda::future<empty>;
    future_type1 f1 = agency::cuda::make_ready_future(empty());

    using future_type2 = agency::cuda::future<void>;
    future_type2 f2(std::move(f1));

    assert(!f1.valid());
    assert(f2.valid());
  }

  {
    // empty -> void
    using future_type1 = agency::cuda::future<empty>;
    future_type1 f1 = agency::cuda::make_ready_future(empty());

    using future_type2 = agency::cuda::future<void>;
    future_type2 f2 = agency::future_traits<future_type1>::cast<void>(f1);
  }

//  {
//    using future_type1 = agency::cuda::future<unsigned int>;
//    future_type1 f1 = agency::cuda::make_ready_future(0u);
//
//    using future_type2 = agency::cuda::future<int>;
//    future_type2 f2 = agency::future_traits<future_type2>::cast(f1);
//  }

  std::cout << "OK" << std::endl;

  return 0;
}

new_contents:
#include <agency/cuda/future.hpp>
#include <agency/future.hpp>
#include <iostream>
#include <cassert>

struct empty {};

int main()
{
  {
    // construction of future<void> from empty types

    using future_type1 = agency::cuda::future<empty>;
    future_type1 f1 = agency::cuda::make_ready_future(empty());

    using future_type2 = agency::cuda::future<void>;
    future_type2 f2(std::move(f1));

    assert(!f1.valid());
    assert(f2.valid());
  }

  {
    // empty -> void
    using future_type1 = agency::cuda::future<empty>;
    future_type1 f1 = agency::cuda::make_ready_future(empty());

    using future_type2 = agency::cuda::future<void>;
    future_type2 f2 = agency::future_traits<future_type1>::cast<void>(f1);

    assert(!f1.valid());
    assert(f2.valid());
  }

  {
    using future_type1 = agency::cuda::future<unsigned int>;
    future_type1 f1 = agency::cuda::make_ready_future(13u);

    using future_type2 = agency::cuda::future<int>;
    future_type2 f2 = agency::future_traits<future_type1>::cast<int>(f1);

    // XXX fut.then() needs to invalidate fut
    //assert(!f1.valid());
    assert(f2.get() == 13);
  }

  std::cout << "OK" << std::endl;

  return 0;
}

subject: Add a test for future_traits::cast()

message: Add a test for future_traits::cast()


old_contents:
/*! \file TWFDriverPotentialPairGPU.cu
    \brief Defines the driver functions for computing all types of pair forces
    on the GPU
*/

#include "EvaluatorPairTWF.h"
#include "AllDriverPotentialPairGPU.cuh"
hipError_t gpu_compute_twftemp_forces(
    const pair_args_t& pair_args, const EvaluatorPairTWF::param_type *d_params)
    {
    return gpu_compute_pair_forces<EvaluatorPairTWF>(pair_args,
                                                     d_params);
    }

new_contents:
/*! \file TWFDriverPotentialPairGPU.cu
    \brief Defines the driver functions for computing all types of pair forces
    on the GPU
*/

#include "EvaluatorPairTWF.h"
#include "AllDriverPotentialPairGPU.cuh"
hipError_t gpu_compute_twf_forces(
    const pair_args_t& pair_args, const EvaluatorPairTWF::param_type *d_params)
    {
    return gpu_compute_pair_forces<EvaluatorPairTWF>(pair_args,
                                                     d_params);
    }

subject: Fix typo in GPU TWF force compute function


old_contents:
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#ifndef HL_MATRIX_TYPE_CUH_
#define HL_MATRIX_TYPE_CUH_

#include "hl_base.h"

#ifdef __CUDA_ARCH__
/**
 * CUDA kernel inline function
 */
#define INLINE   __device__ inline
#else
/**
 * CPP inline function
 */
#define INLINE   inline
#endif

#ifdef __CUDA_ARCH__
#include <vector_types.h>
#ifndef PADDLE_TYPE_DOUBLE
typedef float4 vecType;
#else
typedef double2 vecType;
#endif
#elif defined(__SSE3__)
#include "hl_cpu_simd_sse.cuh"
#elif defined(__ARM_NEON) || defined(__ARM_NEON__)
#include "hl_cpu_simd_neon.cuh"
#else
#include "hl_cpu_scalar.cuh"
#endif

#endif  // HL_MATRIX_TYPE_CUH_

new_contents:
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#ifndef HL_MATRIX_TYPE_CUH_
#define HL_MATRIX_TYPE_CUH_

#include "hl_base.h"

#ifdef __CUDA_ARCH__
/**
 * CUDA kernel inline function
 */
#define INLINE   __device__ inline
#else
/**
 * CPP inline function
 */
#define INLINE   inline
#endif

#ifdef __CUDA_ARCH__
#include <vector_types.h>
#ifndef PADDLE_TYPE_DOUBLE
typedef float4 vecType;
#else
typedef double2 vecType;
#endif
#elif defined(__SSE3__)
#include "hl_cpu_simd_sse.cuh"
#elif (defined(__ARM_NEON) || defined(__ARM_NEON__)) && !defined(__NVCC__)
#include "hl_cpu_simd_neon.cuh"
#else
#include "hl_cpu_scalar.cuh"
#endif

#endif  // HL_MATRIX_TYPE_CUH_

subject: Disable neon when enable gpu.

message: Disable neon when enable gpu.


new_contents:
#include <unittest/unittest.h>

#include <thrust/detail/config.h>
#include <thrust/detail/caching_allocator.h>

template<typename Allocator>
void test_implementation(Allocator alloc)
{
    typedef typename thrust::detail::allocator_traits<Allocator> Traits;
    typedef typename Allocator::pointer Ptr;

    Ptr p = Traits::allocate(alloc, 123);
    Traits::deallocate(alloc, p, 123);

    Ptr p2 = Traits::allocate(alloc, 123);
    ASSERT_EQUAL(p, p2);
}

void TestSingleDeviceTLSCachingAllocator()
{
    test_implementation(thrust::detail::single_device_tls_caching_allocator());
};
DECLARE_UNITTEST(TestSingleDeviceTLSCachingAllocator);

message:
Add a unit test for the convenient caching allocator in detail.

Reviewed-by: Bryce Adelstein Lelbach aka wash <2f0f95f95a80179c2180af4c82f6ea311b6bd2c8@gmail.com>


new_contents:
#include <unittest/unittest.h>
#include <thrust/memory.h>

struct my_tag : thrust::device_system_tag {};

template<typename T1, typename T2>
bool is_same(const T1 &, const T2 &)
{
  return false;
}

template<typename T>
bool is_same(const T &, const T &)
{
  return true;
}

void TestSelectSystemDifferentTypes()
{
  // XXX different systems handle this differently, so it's impossible to test it right now
  KNOWN_FAILURE;
}
DECLARE_UNITTEST(TestSelectSystemDifferentTypes);

void TestSelectSystemSameTypes()
{
  using thrust::system::detail::generic::select_system;

  // select_system(device_system_tag, device_system_tag) should return device_system_tag
  bool is_device_system_tag = is_same(thrust::device_system_tag(), select_system(thrust::device_system_tag(), thrust::device_system_tag()));
  ASSERT_EQUAL(true, is_device_system_tag);

  // select_system(my_tag, my_tag) should return my_tag
  bool is_my_tag = is_same(my_tag(), select_system(my_tag(), my_tag()));
  ASSERT_EQUAL(true, is_my_tag);
}
DECLARE_UNITTEST(TestSelectSystemSameTypes);

message:
Add unit tests for select_system, with one KNOWN_FAILURE

Fixes #169


new_contents:
// RUN: %clang_cc1 %s -triple nvptx-unknown-unknown -fcuda-is-device -emit-llvm -o - | FileCheck %s

#include "../SemaCUDA/cuda.h"

#define MAX_THREADS_PER_BLOCK 256
#define MIN_BLOCKS_PER_MP     2

// Test both max threads per block and Min cta per sm.
extern "C" {
__global__ void
__launch_bounds__( MAX_THREADS_PER_BLOCK, MIN_BLOCKS_PER_MP )
Kernel1()
{
}
}

// CHECK: !{{[0-9]+}} = metadata !{void ()* @Kernel1, metadata !"maxntidx", i32 256}
// CHECK: !{{[0-9]+}} = metadata !{void ()* @Kernel1, metadata !"minctasm", i32 2}

// Test only max threads per block. Min cta per sm defaults to 0, and
// CodeGen doesn't output a zero value for minctasm.
extern "C" {
__global__ void
__launch_bounds__( MAX_THREADS_PER_BLOCK )
Kernel2()
{
}
}

// CHECK: !{{[0-9]+}} = metadata !{void ()* @Kernel2, metadata !"maxntidx", i32 256}

subject: Add test case for r206302

message:
Add test case for r206302

git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@206303 91177308-0d34-0410-b5e6-96231b3b80d8


new_contents:
// REQUIRES: clang-driver

// Check that we raise an error if we're trying to compile CUDA code but can't
// find a CUDA install, unless -nocudainc was passed.

// RUN: %clang -### --sysroot=%s/no-cuda-there %s 2>&1 | FileCheck %s --check-prefix ERR
// RUN: %clang -### --cuda-path=%s/no-cuda-there %s 2>&1 | FileCheck %s --check-prefix ERR
// ERR: cannot find CUDA installation

// RUN: %clang -### -nocudainc --sysroot=%s/no-cuda-there %s 2>&1 | FileCheck %s --check-prefix OK
// RUN: %clang -### -nocudainc --cuda-path=%s/no-cuda-there %s 2>&1 | FileCheck %s --check-prefix OK
// OK-NOT: cannot find CUDA installation

message:
[CUDA] Add a test for r266496 (raise an error if a CUDA installation isn't found)

git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@266796 91177308-0d34-0410-b5e6-96231b3b80d8


new_contents:
#include <agency/cuda/grid_executor.hpp>
#include <algorithm>
#include <iostream>

__managed__ int increment_me;

struct increment_and_return_void
{
  template<class Index>
  __device__
  void operator()(const Index&, int& past)
  {
    atomicAdd(&increment_me, past);
  }
};

template<class Executor>
void test()
{
  using executor_type = Executor;

  using traits = agency::executor_traits<executor_type>;

  {
    // then_execute returning user-specified container

    executor_type exec;

    typename executor_type::shape_type shape{10,10};

    auto past = traits::template make_ready_future<int>(exec, 13);

    using container_type = typename executor_type::template container<int>;

    using index_type = typename executor_type::index_type;

    auto fut = traits::template then_execute<container_type>(exec, [] __device__ (index_type idx, int& past)
    {
      return past;
    },
    shape,
    past);

    auto got = fut.get();

    assert(got == std::vector<int>(got.size(), 13));
  }

  {
    // then_execute returning default container

    executor_type exec;

    typename executor_type::shape_type shape{10,10};

    auto past = traits::template make_ready_future<int>(exec, 13);

    using index_type = typename traits::index_type;

    auto fut = traits::then_execute(exec, [] __device__ (index_type idx, int& past)
    {
      return past;
    },
    shape,
    past);

    auto result = fut.get();

    std::vector<int> ref(result.size(), 13);
    assert(std::equal(ref.begin(), ref.end(), result.begin()));
  }

  {
    // then_execute returning void

    executor_type exec;

    typename executor_type::shape_type shape{10,10};

    auto past = traits::template make_ready_future<int>(exec, 13);

    increment_me = 0;

    using index_type = typename traits::index_type;

    // XXX don't use a __device__ lambda here because we can't reliably compute its return type
    auto fut = traits::then_execute(exec, increment_and_return_void(), shape, past);

    fut.wait();

    assert(increment_me == shape[0] * shape[1] * 13);
  }
}

int main()
{
  // a completely empty executor
  test<agency::cuda::grid_executor>();

  std::cout << "OK" << std::endl;

  return 0;
}

subject: Test multi-agent then_execute without shared parameters with nvcc


new_contents:
#include <thrust/random.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/functional.h>
#include <thrust/transform_reduce.h>

#include <iostream>

// The technique demonstrated in the example monte_carlo.cu
// assigns an independently seeded random number generator to each
// of 30K threads, uses a simple hashing scheme based on thread index to
// seed each RNG. This technique, while simple, may be succeptible
// to correlation among the streams of numbers generated by each RNG
// because there is no guarantee that the streams are not disjoint.
// This example demonstrates a slightly more sophisticated technique
// which ensures that the subsequences generated in each thread are
// disjoint with no overlap. To achieve this, we use a single common stream
// of random numbers, but partition it among threads to ensure no overlap
// of substreams. The substreams are generated procedurally using
// default_random_engine's discard(n) member function, which skips
// past n states of the RNG. This function is accelerated and executes
// in O(lg n) time.

// use 30K subsequences of random numbers
const int M = 30000;

struct estimate_pi : public thrust::unary_function<unsigned int,float>
{
  __host__ __device__
  float operator()(unsigned int thread_id)
  {
    float sum = 0;
    unsigned int N = 5000; // samples per stream

    // note that M * N <= default_random_engine::max,
    // which is also the period of this particular RNG
    // this ensures the substreams are disjoint

    // create a random number generator
    // note that each thread uses an RNG with the same seed
    thrust::default_random_engine rng;

    // jump past the numbers used by the subsequences before me
    rng.discard(N * thread_id);

    // create a mapping from random numbers to [0,1)
    thrust::uniform_real_distribution<float> u01(0,1);

    // take N samples in a quarter circle
    for(unsigned int i = 0; i < N; ++i)
    {
      // draw a sample from the unit square
      float x = u01(rng);
      float y = u01(rng);

      // measure distance from the origin
      float dist = sqrtf(x*x + y*y);

      // add 1.0f if (u0,u1) is inside the quarter circle
      if(dist <= 1.0f)
        sum += 1.0f;
    }

    // multiply by 4 to get the area of the whole circle
    sum *= 4.0f;

    // divide by N
    return sum / N;
  }
};

int main(void)
{
  float estimate = thrust::transform_reduce(thrust::counting_iterator<int>(0),
                                            thrust::counting_iterator<int>(M),
                                            estimate_pi(),
                                            0.0f,
                                            thrust::plus<float>());
  estimate /= M;

  std::cout << "pi is around " << estimate << std::endl;

  return 0;
}

subject: Add an example of Monte Carlo using disjoint subsequences of random numbers from a common stream.


new_contents:
// Tests CUDA compilation with -S.

// REQUIRES: clang-driver
// REQUIRES: x86-registered-target
// REQUIRES: nvptx-registered-target

// RUN: %clang -### -S -target x86_64-linux-gnu --cuda-gpu-arch=sm_20 %s 2>&1 \
// RUN:   | FileCheck -check-prefix HOST -check-prefix SM20 %s
// RUN: %clang -### -S -target x86_64-linux-gnu --cuda-host-only -o foo.s %s 2>&1 \
// RUN:   | FileCheck -check-prefix HOST %s
// RUN: %clang -### -S -target x86_64-linux-gnu --cuda-gpu-arch=sm_20 \
// RUN:   --cuda-device-only -o foo.s %s 2>&1 \
// RUN:   | FileCheck -check-prefix SM20 %s
// RUN: %clang -### -S -target x86_64-linux-gnu --cuda-gpu-arch=sm_20 \
// RUN:   --cuda-gpu-arch=sm_30 --cuda-device-only %s 2>&1 \
// RUN:   | FileCheck -check-prefix SM20 -check-prefix SM30 %s

// HOST-DAG: "-cc1" "-triple" "x86_64--linux-gnu"
// SM20-DAG: "-cc1" "-triple" "nvptx64-nvidia-cuda"
// SM20-same: "-target-cpu" "sm_20"
// SM30-DAG: "-cc1" "-triple" "nvptx64-nvidia-cuda"
// SM30-same: "-target-cpu" "sm_30"

// RUN: %clang -### -S -target x86_64-linux-gnu -o foo.s %s 2>&1 \
// RUN:   | FileCheck -check-prefix MULTIPLE-OUTPUT-FILES %s
// RUN: %clang -### -S -target x86_64-linux-gnu --cuda-device-only \
// RUN:   --cuda-gpu-arch=sm_20 --cuda-gpu-arch=sm_30 -o foo.s %s 2>&1 \
// RUN:   | FileCheck -check-prefix MULTIPLE-OUTPUT-FILES %s
// MULTIPLE-OUTPUT-FILES: error: cannot specify -o when generating multiple output files

message:
[CUDA] Add test for compiling CUDA code with -S.

Reviewers: tra

Subscribers: cfe-commits, jhen

Differential Revision: http://reviews.llvm.org/D16081

git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@257810 91177308-0d34-0410-b5e6-96231b3b80d8


new_contents:
#include <agency/cuda/execution_policy.hpp>
#include <agency/cuda/grid_executor.hpp>
#include <thrust/device_vector.h>
#include <cstdio>
#include <cassert>

template<class T>
__device__
T fetch_and_add(T* ptr, T value)
{
#ifdef __NVCC__
  return atomicAdd(ptr, value);
#else
  return __sync_fetch_and_add(ptr, value);
#endif
}

using cuda_thread = agency::parallel_group<agency::cuda::concurrent_agent>;

struct functor
{
  __device__
  void operator()(cuda_thread& self, int* outer_result, int& outer_shared, int& inner_shared)
  {
    printf("idx: {%d, %d}\n", self.outer().index(), self.inner().index());
    printf("outer_shared: %d\n", outer_shared);
    printf("inner_shared: %d\n", inner_shared);

    fetch_and_add(&inner_shared, 1);
    self.inner().wait();

    assert(inner_shared == self.inner().group_size() + 2);

    auto result = fetch_and_add(&outer_shared, 1);

    // exactly one agent will see this result
    if(result == (2 * 2))
    {
      *outer_result = result + 1;
    }
  }
};

int main()
{
  using cuda_thread = agency::parallel_group<agency::cuda::concurrent_agent>;

  auto policy = agency::cuda::par(2, agency::cuda::con(2));

  thrust::device_vector<int> outer_result(1);

  agency::cuda::bulk_invoke(policy, functor(), thrust::raw_pointer_cast(outer_result.data()), agency::share<0>(1), agency::share<1>(2));

  assert(outer_result[0] == (2 * 2 + 1));

  std::cout << "OK" << std::endl;

  return 0;
}

subject: Add CUDA test for shared variables

message: Add CUDA test for shared variables


new_contents:
#include "threadFenceReduction_kernel.cuh"

struct doubleMax {
  TASKCFG double init() {return 0.0;}
  TASKCFG double reduce(double x, double acc){return x > acc ? x : acc;}
  TASKCFG double f(double c){return fabs(c);}
};

extern "C" __global__ void max_512_e2(const double *g_idata, double *g_odata, unsigned int n) {
  retirementCount = 0;
  reduceSinglePass_devGen<512, true, double, double, doubleMax>(g_idata, g_odata, n);
}

subject: Add abs maximum search (the code sits in the wrong directory ATM).


new_contents:
#include <stdio.h>

void __device__
saxpy(float* X, const float* Y, float scale, int n)
{
    for (int i=0; i < n; ++i) // Iterate over cols
        X[i] += Y[i] * scale;
}

void __global__ kernel_add_one(int* a, int length) {
    int gid = threadIdx.x + blockDim.x*blockIdx.x;

    while(gid < length) {
    	a[gid] += 1;
        gid += blockDim.x*gridDim.x;
    }
}

void __global__
mean_pool(float* means__bo,
    const float* X__to, const int* lengths__b, int B, int T, int O)
{
    // Compute means of a batch of concatenated sequences, using the lengths.'''
    int b = blockIdx.x; // Batch-item we're averaging
    if (b >= B) return;

    // Go to the regions we're working on
    for (int i=0; i < b; ++i) {
        means__bo += O;
	X__to += lengths__b[i] * O;
    }

    int length = lengths__b[b];
    // Each invocation of the kernel averages one batch.
    float scale = 1. / length;
    for (int _=0; _ < length; ++_) // Iterate over rows
    {
        saxpy(means__bo, X__to, scale, O);
        X__to += O;
    }
}

void __global__
backprop_mean_pool(float* dX__to, const float* d_means__bo, const int* lengths__b,
    int B, int T, int O)
{
    int b = blockIdx.x; // Batch-item we're averaging
    if (b >= B) return;

    int length = lengths__b[b];
    float scale = 1./ length;

    for (int _=0; _ < length; _++)
    {
        saxpy(dX__to, d_means__bo, scale, O);
        dX__to += O;
        d_means__bo += O;
    }
}

subject: Add kernel for mean pool

message: Add kernel for mean pool


new_contents:
// Tests CUDA compilation with -E.

// REQUIRES: clang-driver
// REQUIRES: x86-registered-target
// REQUIRES: nvptx-registered-target

#ifndef __CUDA_ARCH__
#define PREPROCESSED_AWAY
clang_unittest_no_arch PREPROCESSED_AWAY
#else
clang_unittest_cuda_arch __CUDA_ARCH__
#endif

// CHECK-NOT: PREPROCESSED_AWAY

// RUN: %clang -E -target x86_64-linux-gnu --cuda-gpu-arch=sm_20 %s 2>&1 \
// RUN:   | FileCheck -check-prefix NOARCH %s
// RUN: %clang -E -target x86_64-linux-gnu --cuda-gpu-arch=sm_20 --cuda-host-only %s 2>&1 \
// RUN:   | FileCheck -check-prefix NOARCH %s
// NOARCH: clang_unittest_no_arch

// RUN: %clang -E -target x86_64-linux-gnu --cuda-gpu-arch=sm_20 --cuda-device-only %s 2>&1 \
// RUN:   | FileCheck -check-prefix SM20 %s
// SM20: clang_unittest_cuda_arch 200

// RUN: %clang -E -target x86_64-linux-gnu --cuda-gpu-arch=sm_30 --cuda-device-only %s 2>&1 \
// RUN:   | FileCheck -check-prefix SM30 %s
// SM30: clang_unittest_cuda_arch 300

// RUN: %clang -E -target x86_64-linux-gnu --cuda-gpu-arch=sm_20 --cuda-gpu-arch=sm_30 \
// RUN:   --cuda-device-only %s 2>&1 \
// RUN:   | FileCheck -check-prefix SM20 -check-prefix SM30 %s

message:
[CUDA] Add tests for compiling CUDA files with -E.

Reviewers: tra

Subscribers: cfe-commits, jhen

Differential Revision: http://reviews.llvm.org/D16080

git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@257807 91177308-0d34-0410-b5e6-96231b3b80d8