Skip to content
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

Add 'default-bvh-flag' command line option #599

Merged
merged 5 commits into from
Oct 24, 2018

Conversation

karjonas
Copy link
Contributor

No description provided.

Copy link
Contributor

@tribal-tec tribal-tec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test would be nice :) Showing that less memory is actually used.


enum class BVHType
{
dynamic,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's very ospray centric. what is 'none' even? Shouldn't it be a bitmask also? dynamic + compact sounds reasonable to me. If ospray can't do that, we shouldn't limit it here. 'Static' is missing also to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since optimizations for a particular metric typically go against others, I think it's fair to have a single label to provide a hint about the expected usage.

@@ -510,6 +510,29 @@ bool OSPRayModel::_commitTransferFunction()
return true;
}

void OSPRayModel::_commitBVHType()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ospCommit(_model) is missing then, otherwise the function should be renamed.

@karjonas
Copy link
Contributor Author

How do I query the memory usage of the BVH?

@karjonas
Copy link
Contributor Author

I think checking the ram usage is a bit hard so I added a simpler unit test.

}

template <typename T>
inline bool enumHas(const T eA, const T eB)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

template<typename T>
bool isBitSet(typename std::underlying_type<T>::type mask, const T bit)

@@ -34,4 +36,18 @@ inline auto lowerCase(std::string str)
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
return str;
}

template <typename T>
inline T enumSet(const T eA, const T eB)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
inline T enumSet(const T eA, const T eB)
template <typename T>
inline typename std::underlying_type<T>::type setBit(const std::underlying_type<T>::type mask, const T bit)
{
return mask | static_cast<typename std::underlying_type<T>::type>(bit);
}

You should return the underlying type, because semantically the output value is not the enum anymore.
But even worse, imagine you have this code

enum class A : int { a = 1, b = 2 };
int f(const A a)
{
    switch(a)
    {
        case A::a: return int(a);
        case A::b: return int(a);
    }
}

That code if perfect, but if you call f with something A(17), the function return value will be undefined.

//
(PARAM_DEFAULT_BVH_FLAG.c_str(),
po::value<std::vector<std::string>>()->multitoken(),
"Default bvh type [static|dynamic|compact|robust]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear that you can have multiple flags and what is the token separator.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BVH

@@ -234,6 +234,7 @@ class GeometryParameters : public AbstractParameters
return _morphologyUseSDFGeometries;
}

BVHType getDefaultBVHType() const { return _defaultBVHType; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int getDefaultBVHModes or getDefaultBVHTypeMask


ospSet1i(_model, "dynamicMode", dynamicMode ? 1 : 0);
ospSet1i(_model, "compactMode", compactMode ? 1 : 0);
ospSet1i(_model, "robustMode", robustMode ? 1 : 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ospSet1i(_model, "robustMode", robustMode ? 1 : 0);
ospSet1i(_model, "robustMode", isBitSet(_bvhType, BVHTtype::dynamic));

@@ -97,9 +97,12 @@ class ModelParams : public ModelInstance
const std::string& getName() const { return _name; }
void setPath(const std::string& path) { _updateValue(_path, path); }
const std::string& getPath() const { return _path; }
void setBVHType(BVHType bvhType) { _updateValue(_bvhType, bvhType); }
BVHType getBVHType() const { return _bvhType; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if this parameter goes into the ModelDescriptor property map because then you can set it from the client. I'm not totally sure about the jsonrpc part, maybe @rolandjitsu can comment on this.

Copy link
Contributor

@rolandjitsu rolandjitsu Oct 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add it to the property map it would be rendered without any effort on my side (because it's generated from schema). Otherwise I'd need to add it myself.

But then you have to make sure that when the bvh property on the property map is set, you do your stuff (set the bvh type).

Also, I'm not sure how enums are handled currently for the property map props (if they are).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact it's not an enum, it's a bit mask. From the command line I think it's set as a space separated list of strings. I'd guess you don't have any code for rendering such a thing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we don't handle bit masks.

For multiple selection we'd need some additional info from schema (instead of {type: 'string', enum: ['bla', ...]} has to be {type: 'array', items: {type: 'string', enum: ['bla', ...]}).

And then I'd need to add support for multiple selection.

If this is single selection, then we just need string enums instead of bitmask.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tribal-tec requested it to be a multiple selection, but not all combinations are allowed... Another option is splitting this into multiple properties:

  • BVH update hint: static|dynamic
  • compact BVH: bool
  • robust BVH: bool
    What do you think @karjonas ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be easy to render and we only need to extend the schema to support single selection for a set of values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, let's keep it as it is for the moment and open this can of worms later.

@karjonas karjonas force-pushed the bvh_flag branch 3 times, most recently from d36fbd5 to e12851b Compare October 24, 2018 10:24
Use set instead of bitflags

Remove bvh flags from model params
@karjonas karjonas changed the title Add 'default-bvh' command line flag Add 'default-bvh-flag' command line option Oct 24, 2018
{
_bvhFlags = std::move(bvhFlags);
}
std::set<BVHFlag> getBVHFlags() const { return _bvhFlags; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::set<BVHFlag>&

(PARAM_DEFAULT_BVH_FLAG.c_str(),
po::value<std::vector<std::string>>()->multitoken(),
"Sets one or more property flags to be used by default when creating "
"a bvh [dynamic|compact|robust]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BVH
Same as before, it's not clear that this is a list? Or does boost program_options take care of indicating it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to explain it without a wall of text.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Set a default flag to apply to BVH creation, one of [dynamic|compact|robust], may appear multiple times."

I'm not sure whether --default-bvh-flag "dynamic robust" is also accepted though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, the message is not totally accurate, but at least it doesn't miss the possibility of setting multiple flags.

if (kv != BVH_TYPES.end())
_defaultBVHFlags.insert(kv->second);
else
throw std::runtime_error("Invalid bvh type '" + bvh + "'.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type -> flag

const bool compactMode = _bvhFlags.count(BVHFlag::compact);
const bool robustMode = _bvhFlags.count(BVHFlag::robust);

ospSet1i(_model, "dynamicMode", dynamicMode ? 1 : 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ospSet1i(_model, "dynamicMode", dynamicMode ? 1 : 0);
ospSet1i(_model, "dynamicMode", _bvhFlags.count(BVHFlag::dynamic));

const char* app = testSuite.argv[0];
const char* argv[] = {
app, "demo", "--default-bvh-flag", "robust", "--default-bvh-flag",
"compact",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have never guessed this is how you provide multiple flags through the command line...

@karjonas karjonas merged commit 9cc4564 into BlueBrain:master Oct 24, 2018
@karjonas karjonas deleted the bvh_flag branch October 24, 2018 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants