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

misc: Add deviceid to configuration and enhance switchconfig #2175

Merged
merged 6 commits into from
Aug 4, 2023

Conversation

ccuetom
Copy link
Contributor

@ccuetom ccuetom commented Jul 28, 2023

Adds deviceid to configuration and updates switchconfig so that it can act both as a decorator and a context manager.

@mloubout mloubout added the arch jitting, archinfo, ... label Jul 28, 2023
Copy link
Contributor

@FabioLuporini FabioLuporini left a comment

Choose a reason for hiding this comment

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

The changes in switchconfig are solid -- thanks!

My only request here is to edit DeviceID (see comment in review)

@@ -252,7 +252,7 @@ class DeviceID(DeviceSymbol):

@property
def default_value(self):
return -1
return configuration['deviceid']
Copy link
Contributor

Choose a reason for hiding this comment

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

We can return a default_value based on global state

I think the better way to go here would be overriding _arg_values (from Scalar)

Within the override, we check, in order:

  • whether kwargs has a user-override for deviceid
  • whether configuration['deviceid'] is != default_value
  • else return default_value

@@ -7,6 +7,7 @@
from devito.logger import info, warning
from devito.tools import Signer, filter_ordered


Copy link
Contributor

Choose a reason for hiding this comment

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

?

@@ -1186,7 +1186,9 @@ def parse_kwargs(**kwargs):

# `allocator`
kwargs['allocator'] = default_allocator(
'%s.%s' % (kwargs['compiler'].__class__.__name__, kwargs['language'])
'%s.%s.%s' % (kwargs['compiler'].__class__.__name__,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just make a name property in our Compilers so we don't have to do this

self.previous = {}
for k, v in self.params.items():
self.previous[k] = configuration[k]
configuration[k] = v
Copy link
Contributor

Choose a reason for hiding this comment

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

self.previous = self.params.copy()
configuration.update(**self.params)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this has a slightly different effect, although I could write it more succinctly:

self.previous = {k: configuration[k] for k in self.params.keys()}
configuration.update(**self.params)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, configuration.update(**self.params) doesn't work, since the update method has a different meaning in configuration

try:
configuration[k] = self.previous[k].name
except AttributeError:
super(Parameters, configuration).__setitem__(k, self.previous[k])
Copy link
Contributor

Choose a reason for hiding this comment

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

How can we end up here? isn't this line 247?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not exactly, this bypasses the @_check_key_value decorator and the _update_functions callback. The value we're setting back into the configuration has already gone through those and in some cases (e.g. compiler and platform) it has been transformed. So the previous checks and transformations need to be skipped.

elif configuration['deviceid'] != self.default_value:
return {self.name: configuration['deviceid']}
else:
return {self.name: self.default_value}
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just {self.name: kwargs.pop(self.name, self.default_value)} and have default_value return configuration['deviceid']

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isn't that what the original code did? I thought the idea was to keep default_value and configuration['deviceid'] separate?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, agree with Carlos here. We can't just return a (mutable) global value from default_value :-)

@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Merging #2175 (7a69ab2) into master (0abe395) will decrease coverage by 0.01%.
The diff coverage is 79.31%.

@@            Coverage Diff             @@
##           master    #2175      +/-   ##
==========================================
- Coverage   87.10%   87.09%   -0.01%     
==========================================
  Files         226      226              
  Lines       40148    40160      +12     
  Branches     7325     7329       +4     
==========================================
+ Hits        34969    34979      +10     
- Misses       4600     4602       +2     
  Partials      579      579              
Files Changed Coverage Δ
devito/operator/operator.py 89.59% <ø> (+1.09%) ⬆️
devito/types/parallel.py 83.01% <16.66%> (-2.61%) ⬇️
devito/parameters.py 85.10% <94.11%> (-0.71%) ⬇️
devito/__init__.py 94.52% <100.00%> (+0.15%) ⬆️
devito/arch/compiler.py 38.52% <100.00%> (-0.04%) ⬇️
devito/logger.py 78.18% <100.00%> (+0.40%) ⬆️

Copy link
Contributor

@georgebisbas georgebisbas left a comment

Choose a reason for hiding this comment

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

I guess no tests are needed for this PR for this new functionality?

@mloubout mloubout merged commit bc4d02d into devitocodes:master Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch jitting, archinfo, ...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants