SYCLomatic icon indicating copy to clipboard operation
SYCLomatic copied to clipboard

error: assigning to 'void (*)(const int *, int *, int)' from incompatible type 'void (const int *, int *, int, const sycl::nd_item<3> &, int *)': different number of parameters (3 vs 5)

Open zjin-lcf opened this issue 2 years ago • 1 comments

Compiling the migrated program produces a few errors. Thanks.

Please see the pasted Cuda program.

/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *  * Neither the name of NVIDIA CORPORATION nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#define THREAD_N 256
#define N 1024
#define DIV_UP(a, b) (((a) + (b) - 1) / (b))

// Includes, system
#include <stdio.h>
#define OUTPUT_ATTR(attr)                                         \
  printf("Shared Size:   %d\n", (int)attr.sharedSizeBytes);       \
  printf("Constant Size: %d\n", (int)attr.constSizeBytes);        \
  printf("Local Size:    %d\n", (int)attr.localSizeBytes);        \
  printf("Max Threads Per Block: %d\n", attr.maxThreadsPerBlock); \
  printf("Number of Registers: %d\n", attr.numRegs);              \
  printf("PTX Version: %d\n", attr.ptxVersion);                   \
  printf("Binary Version: %d\n", attr.binaryVersion);

bool check_func1(int *hInput, int *hOutput, int a) {
  for (int i = 0; i < N; ++i) {
    int cpuRes = hInput[i] * a + i;

    if (hOutput[i] != cpuRes) {
      return false;
    }
  }

  return true;
}

__global__ void simple_kernel(const int *pIn, int *pOut, int a) {
  __shared__ int sData[THREAD_N];
  int tid = threadIdx.x + blockDim.x * blockIdx.x;

  sData[threadIdx.x] = pIn[tid];
  __syncthreads();

  pOut[tid] = sData[threadIdx.x] * a + tid;
  ;
}
int main(int argc, const char *argv[]) {
  int *hInput = NULL;
  int *hOutput = NULL;
  int *dInput = NULL;
  int *dOutput = NULL;

  // Allocate device memory
  cudaMalloc(&dInput, sizeof(int) * N * 2);
  cudaMalloc(&dOutput, sizeof(int) * N);

  // Allocate host memory
  cudaMallocHost(&hInput, sizeof(int) * N * 2);
  cudaMallocHost(&hOutput, sizeof(int) * N);

  for (int i = 0; i < N * 2; i++) {
    hInput[i] = i;
  }

  // Copy data from host to device
  cudaMemcpy(dInput, hInput, sizeof(int) * N * 2, cudaMemcpyHostToDevice);

  // Test C++ overloading
  bool testResult = true;
  bool funcResult = true;
  int a = 1;

  void (*func1)(const int *, int *, int);
  struct cudaFuncAttributes attr;

  // overload function 1
  func1 = simple_kernel;
  memset(&attr, 0, sizeof(attr));
  //cudaFuncSetCacheConfig(*func1, cudaFuncCachePreferShared);
  cudaFuncGetAttributes(&attr, *func1);
  OUTPUT_ATTR(attr);
  (*func1)<<<DIV_UP(N, THREAD_N), THREAD_N>>>(dInput, dOutput, a);
  cudaMemcpy(hOutput, dOutput, sizeof(int) * N, cudaMemcpyDeviceToHost);
  funcResult = check_func1(hInput, hOutput, a);
  printf("simple_kernel(const int *pIn, int *pOut, int a) %s\n\n",
         funcResult ? "PASSED" : "FAILED");
  testResult &= funcResult;

  cudaFree(dInput);
  cudaFree(dOutput);
  cudaFreeHost(hOutput);
  cudaFreeHost(hInput);

  exit(testResult ? EXIT_SUCCESS : EXIT_FAILURE);
}

zjin-lcf avatar Apr 11 '23 20:04 zjin-lcf

@zjin-lcf launching kernel with function pointer is not supported now, while we plan to support it in the future.

tomflinda avatar Apr 13 '23 03:04 tomflinda

@tomflinda is there a timeline for function pointer support?

richardnorth3 avatar Sep 16 '24 13:09 richardnorth3

@tomflinda currently not.

tomflinda avatar Sep 23 '24 07:09 tomflinda