-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate ParamMap (#7121) #7357
Conversation
This PR deprecates ParamMap for Halide 16, with the plan of removing it entirely for Halide 17; it was added to provide a threadsafe way to provide parameteres to the JIT, but `compile_to_callable()` now does this in a much less intrusive way.
using namespace Halide; | ||
using namespace Halide::Tools; | ||
|
||
// The Halide compiler is currently not guaranteed to be thread safe. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty scary claim. Can we be more precise? Does this test actually share Halide objects across multiple threads? If not, it should be safe. I think the issue with simd_op_check was that it did.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking into history, the thread-unsafety we had was this: https://github.com/halide/Halide/pull/3914/files
Sharing objects between multiple threads and calling non-const methods on them breaks. But that's true of most libraries.
To my understanding, currently without ParamMap, we can't have set parameters programmatically. |
Can you post an example of how you're using ParamMap? We should be able to enable equivalent functionality somehow. |
Something like that: Func f = GetFunc();
Pipeline p( f );
Buffer<f32> oHInputsA( ... );
Buffer<f32> oHKernel( ... );
f32 fParam = ...;
Buffer<f32> aHOutputs( ... );
ParamMap params;
///
params.set(src, oHInputsA);
params.set(kernel, oHKernel);
params.set(param0, 5);
params.set(param1, fValue);
///
p.realize(aHOutputs, t, params); Where what's between '///' is generated via a data driven system. |
Is this machine-generated source code, or does the bit between the /// markers stand in for a for loop over parameters or something? If it's machine-generated source, surely it's easy enough to just generate code that uses |
More a loop. Something like that? void const* pData[5];
pData[0] = &oHInputsA;
pData[1] = &oHKernel;
int five = 5;
pData[2] = &five;
pData[3] = &fValue;
pData[4] = &aHOutputs;
std::vector< Argument > args = { src, kernel, param0, param1 };
Callable c = p.compile_to_callable( t, args );
c( 5, &pData[0] ); |
Basically yeah, but the first argument needs to be a
|
Can you expand a bit on why using |
Is this ready to land, or do we have more concerns about breaking existing users? |
I wasn't aware of 'call_argv_fast' which seem a good replacement, just curious is that still work for buffer in GPU, do we still have a way to have set_host_dirty etc? Because for GPU clearly it's not raw_buffer we need. |
Callable should work just as well as Both halide_buffer_t and Halide::Runtime::Buffer() have set_host_dirty() etc methods. |
Thanks |
Another comment, I mean in a larger system, we would like to store a Callable for later usage. struct SingleFunc
{
Pipeline oPipeline;
Callable oCallable;
Callable* pCallable;
}; It's not possible to have: Do you have any comment on that? |
It has the same storage requirements as every other piece of Halide IR -- e.g.,
If you can store a Pipeline there, you should be able to store a Callable. What is the specific error you are getting? Also: why do you want/need to store a |
Callable have a default constructor as private: struct SingleFunc
{
Callable oCallable; // So this do not compile
}; So: |
It's possible to use a struct like that with types that don't have public default constructors by not default-constructing the struct. But that's sort of a pain. If we want Callable to act like other front-end types, we should make it nullable, by making the default constructor public and add a .defined() method. |
My struct contains other stuff I need my default constructor. |
That's what we'll do, PR on the way |
Thanks a lot |
@soufianekhiat -- the fixes for Callable have landed. Please check them out and let us know if this will make Callable an acceptable replacement for ParamMap -- I don't want to land this until I hear back :-) |
I'm still testing, on 4a80251. // Before ImageParam p( f32, 0, "input" );
Func f{ "naive" };
f() = p(); Pipeline p( f );
p.compile_jit( oTarget );
oHOutput, oTarget, oParams
ParamMap oParams;
f32 five = 5.0f;
Buffer<> buff = Buffer<>::make_scalar( &five, "p_input" );
oParams.set( p, buff );
Buffer<> output = Buffer<>::make_scalar( Float( 32 ), "output" );
p.realize( output, oTarget, oParams ); // Now: Pipeline p( f );
Callable oCallable = p.compile_to_callable( { p }, oTarget ); I got an exception, with exception & HL_DEBUG_CODEGEN=1:
Still debugging my code |
Thank you for looking into this, I really appreciate it. Please keep me up to date. |
The arguments to |
Monday review ping -- I'm going to land this if I don't hear back from @soufianekhiat soon |
I'm still working on convert my the code.
Currently I'm crashing on random memory, I'll rebuild Halide on debug to track the issue. If it's urgent you can merge it until it's not removed, and we can continue on a discussion/issues somewhere else. |
No, it's not urgent, thanks for your response. It would be better to wait and be sure that you have a workable solution. |
(Just back from vacation -- wanted to check in with @soufianekhiat to see if there's any update. Still no rush.) |
Monday Morning Review Ping. |
Hi, |
Finally, I was able to convert my system by using call_argv_fast. |
ParamMap was deprecated in Halide 16; per #7357, we should go ahead and remove it for Halide 17, in favor of `compile_to_callable()`.
ParamMap was deprecated in Halide 16; per #7357, we should go ahead and remove it for Halide 17, in favor of `compile_to_callable()`.
* Deprecate ParamMap (halide#7121) This PR deprecates ParamMap for Halide 16, with the plan of removing it entirely for Halide 17; it was added to provide a threadsafe way to provide parameteres to the JIT, but `compile_to_callable()` now does this in a much less intrusive way. * Updated comments, removed mutexes (mutices?) * formatting * Go back to HALIDE_ATTRIBUTE_DEPRECATED
ParamMap was deprecated in Halide 16; per halide#7357, we should go ahead and remove it for Halide 17, in favor of `compile_to_callable()`.
This PR deprecates ParamMap for Halide 16, with the plan of removing it entirely for Halide 17; it was added to provide a threadsafe way to provide parameteres to the JIT, but
compile_to_callable()
now does this in a much less intrusive way.