Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

thrust::system::cuda::detail::deallocation_fn type mismatch with cudaFree #1458

@Mochimazui

Description

@Mochimazui

Using VS2019 Version 16.10.1 and thurst code from CUDA 11.3.1 installation.

Build failes on "thrust/system/cuda/memory_resource.h:87" with error a value of type "cudaError_t (*)(void *)" cannot be used to initialize an entity of type "deallocation_fn"

typedef detail::cuda_memory_resource<cudaMalloc, cudaFree,
        thrust::cuda::pointer<void> >
        device_memory_resource;

cudaFree type is enum cudaError (__stdcall*)(void *) but deallocation_fn type is enum cudaError (__cdecl*)(void *).

Seems we need add __stdcall to deallocation_fn, or modify cuda_memory_resource template to allow both __cdecl and __stcall function pointer here.

Code:

#include <cstdio>
#include <typeinfo>

#include <cuda.h>
#include <cuda_runtime.h>
#include <driver_types.h>

#include <thrust/device_vector.h>

int main()
{
    thrust::device_vector<int> a;

    printf("cudaFree: %s\n", typeid(cudaFree).name());
    printf("&cudaFree: %s\n", typeid(&cudaFree).name());

    typedef cudaError_t(* deallocation_fn_0)(void*);
    printf("deallocation_fn: %s\n", typeid(deallocation_fn_0).name());

    typedef cudaError_t(__stdcall * deallocation_fn_1)(void*);
    printf("fixed deallocation_fn: %s\n", typeid(deallocation_fn_1).name());
    
    return 0;
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions