I’m developing a custom POP with CUDA functionality, and I want to create some new point attributes that hold computation results. i am currently instancing the buffer as such:
// create new output buffer for test data
POP_BufferInfo testinfo;
testinfo.location = POP_BufferLocation::CUDA;
testinfo.stream = myStream;
testinfo.mode = POP_BufferMode::ReadWrite;
testinfo.size = sizeof(Position) * NUMBER_OF_INPUT_ATTRIBUTES;
OP_SmartRef<POP_Buffer> testBuf = myContext->createBuffer(testinfo, nullptr);
where NUMBER_OF_INPUT_ATTRIBUTES is currently retrieved from maxInfo.points, if greater than zero (standard checks for inputs being present or not prevent buffer creation if no correct input was found). I was wondering if there’s a better way to do it, or safer.
afaik, there’s nothing about this in headers (specifically, POP_BufferInfo::size isn’t commented at all), and the official samples don’t give much either: CudaPOP does not create new attributes but focuses on retrieving existing ones from inputs; SimpleShapesPOP shows how to create buffers and (implicitly) that size wants a dimension in bytes, but the size is fixed and not bound to input attribute dimensions. Write a CPlusPlus POP | Derivative is also vague about buffer and attribute creation.
following this topic, it would be wonderful to improve headers/documentation about the topics I mentioned. I’m not that experienced, but I’d be happy to help if I can.
For added flexibility, the size of the buffer can be bigger than the required size, which is why it is not bound to the attribute dimension. However it needs to be at least the required size to hold the number of elements for the attribute (you’ll get an error otherwise when loading the dll).
And as you pointed the size has to be provided in bytes.
if the attribute is a point attribute and a single float, the minimum size is
numPoints * sizeof(float)
if the attribute is a point attribute and a vector of 4 floats the minimum size would be
numPoints * sizeof(float) * 4
I’m a little confused regarding what you are trying to achieve.
Which data do you want to hold with the buffer created with testinfo?
If you want to create multiple attributes, you need to create one buffer per attribute.
Let me know if that clarifies things a bit. We may try to provide a cuda example that creates a new attribute based on existing ones as well.
thanks, indeed it does and it’d be really cool to have another official example to use as reference.
that’s some bad naming from my side. I meant exactly numPoints, and instead of NUMBER_OF_INPUT_ATTRIBUTES I should’ve used something like NUMBER_OF_ATTRIBUTE_ELEMENTS.
// CudaPOP.cpp excerpt from official Samples/CPlusPlus/CudaPOP/
m_context->beginCUDAOperations(nullptr);
for (auto& attr : pointAttrs)
{
if (attr.first == "P")
{
void* newDst = nullptr;
// Uncomment this define to see how to create a buffer that you can fill in and send as the result instead
//#define COPY_EXAMPLE
#ifdef COPY_EXAMPLE
POP_BufferInfo createInfo;
createInfo = attr.second->info;
OP_SmartRef<POP_Buffer> newPos = myContext->createBuffer(createInfo, nullptr);
newDst = newPos->getData(nullptr);
#endif
shiftZPosition(attr.second, newDst, infoBufs.pointInfo, infoBufs.maxInfo, m_stream);
#ifdef COPY_EXAMPLE
attr.second = std::move(newPos);
#endif
break;
}
}
m_context->endCUDAOperations(nullptr);
which actually already shows how to do it.
still, it’d be handy to have an example that shows how to deal with the buffer size and infobufs “from scratch” instead of reusing input ones (e.g. in case I want to create a new attribute, not replacing one), or some documentation resource that points the size requirements out, or what should be the expected value when inspecting an input’s BufferInfo, … :))