Hi,
I’m trying to import a directx textures in cuda, this textures are created by Unreal.
For some exotic resolution cudaImportExternalMemory return cudaErrorIllegalAddress
for the second texture recieved.
Info:
the texture are created once and never destroyed.
My code is:
struct DX12TexData
{
unsigned int uniqueId = 0; // data unique identifier
void* handle; // directx 12 texture handle
ID3D12Resource* resource; // directx 12 texture resource
unsigned long long memSize; // texure memory size in bytes
unsigned long long rowPitch;// row pitch in bytes
unsigned long long rowSize; // row size in bytes
};
struct CudaMemory
{
void* m_cudaMem = nullptr;
size_t m_memSize = 0;
size_t m_rowPitch = 0;
size_t m_rowSize = 0;
bool m_isReallocated = false;
explicit operator bool()const
{
return m_cudaMem != nullptr;
}
};
struct CudaMappedMemory : CudaMemory
{
void* handle = nullptr;
cudaExternalMemory_t mappedMemory = nullptr;
};
std::unordered_map<unsigned int, CudaMappedMemory> m_externFloat16;
bool createExternalMemory(const DX12TexData& d3d12Texture)
{
cudaExternalMemoryHandleDesc memDesc{};
memset(&memDesc, 0, sizeof(memDesc));
memDesc.type = cudaExternalMemoryHandleTypeD3D12Resource;
memDesc.handle.win32.handle = d3d12Texture.handle;
memDesc.size = d3d12Texture.memSize;
memDesc.flags = cudaExternalMemoryDedicated;
m_externFloat16[d3d12Texture.uniqueId].handle = d3d12Texture.handle;
const cudaError_t cudaError = cudaImportExternalMemory(&m_externFloat16[d3d12Texture.uniqueId].mappedMemory, &memDesc);
if (cudaError != cudaSuccess)
{
OptroLogger::Error(CURRENT_SOURCES_LOCATION, "cuda error [cudaImportExternalMemory]: %s", cudaGetErrorName(cudaError));
return false;
}
return true;
}
In 800x800 OK
In 1024x1024 OK
In 600x600 OK
In 900x900 KO
In 904x904 KO
In 500x500 KO
Do you have any idea ?
thanks.