If I use this code in the .cu PROGRAM:
rtBuffer<float4, 2> tex_buffer;
...
uint2 xy;
xy.x = 0; // yet for test, so that its guaranteed to be in-range
xy.y = 0; // yet for test, so that its guaranteed to be in-range
const float3 Kd = make_float3(tex_buffer[xy]);
still this exception occurs:
OptiX Error: ‘Unknown error (Details: Function “_rtContextLaunch2D” caught exception: Encountered a CUDA error: cudaDriver().CuMemcpyDtoHAsync( dstHost, srcDevice, byteCount, hStream.get() ) returned (700): Illegal address)’ And on my system the app cannot be closed; when trying to reboot a freeze occurred before I adjusted TDR
cudaGraphicsD3D11RegisterResource, cudaGraphicsMapResources, cudaGraphicsResourceGetMappedPointer all succeed.
devPTR=204a00000h seems to be a valid GPU device pointer
cudaGraphicsUnmapResources and cudaGraphicsUnmapResources also succeed.
Host Code:
ID3D11Resource* pTexRes = NULL;
{
void* PPMtex = loadFloat4BufferTexFromPPMfile("data/grid.ppm"); // loads a ppm to a float4 CPU RAM buffer (4 floats per pixel)
int texwid = 64; // grid.ppm from the OptiX 5.0.0 SDK is 64x64 (so for test its constant here)
int texhei = 64;
ID3D11Buffer *Buf = NULL;
D3D11_BUFFER_DESC bufDesc = {};
D3D11_SUBRESOURCE_DATA bufInitData = {};
bufDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
bufDesc.ByteWidth = texwid * texhei * 16;
bufDesc.CPUAccessFlags = 0;
bufDesc.MiscFlags = 0;
bufDesc.Usage = D3D11_USAGE_IMMUTABLE;
bufInitData.pSysMem = PPMtex;
hr = dev->CreateBuffer(&bufDesc, &bufInitData, ppBuf);
pTexRes = (ID3D11Resource*)pBuf;
}
if (pTexRes)
{
cudaGraphicsResource * CUDAres = NULL;
CUstream hStream = 0;
cudaError_t r = cudaGraphicsD3D11RegisterResource(&CUDAres, pTexRes, cudaGraphicsRegisterFlagsNone);
if (!r)
{
r = cudaGraphicsMapResources(1, &CUDAres, hStream);
if (!r)
{
// OptiX related:
{
optix::Buffer buffer;
void* devPTR = NULL;
size_t size = 0;
buffer = context->createBuffer(RT_BUFFER_INPUT_OUTPUT | RT_BUFFER_GPU_LOCAL, RT_FORMAT_FLOAT4, texwid, texhei);
r = cudaGraphicsResourceGetMappedPointer(&devPTR, &size, CUDAres);
if (!r)
{
buffer->setDevicePointer(OptiXdevice, devPTR);
context["tex_buffer"]->set(buffer);
} // if (!r) after cudaGraphicsResourceGetMappedPointer
// EDIT: seems to be wrong here: r = cudaGraphicsUnmapResources(1, &CUDAres, hStream);
}
} // if (!r) after cudaGraphicsMapResources
// EDIT: seems to be wrong here: r = cudaGraphicsUnregisterResource(CUDAres);
} // if (!r) after cudaGraphicsD3D11RegisterResource
// EDIT: seems to be wrong here: SAFE_RELEASE(pTexRes);
} // if (pTexRes)
However, so I still have to use the PCIE-based solution.
my current system info:
Device: GTX 1050 Driver: 390.77 (Jan 29 2018)
OptiX 5.0 with CUDA Toolkit 9.1.85 on Visual Studio 2017 Community 15.5.6 (toolset v140 of VS2015)
on Windows10 PRO 64bit (still Anniversary Update version 1607 build 14393.1593)
Win SDK Target Platform 10.0.14393.0
OptiX 5.0.0
CUDA 9.1.85 + Patch 1 (Released Jan 25, 2018)