Skip to content

Revise where xp should and shouldn't be used #403

@yousefmoazzam

Description

@yousefmoazzam

The xp variable was introduced to deal with places where either numpy or cupy would work.

However, over time, the usage of xp has crept into places where what is being accessed would not work if xp = numpy. I think it would be better to not overly rely on xp where possible, so combing through the repo and weeding out unnecessary/incorrect uses of it would be helpful.

Two examples

  1. using xp.cuda.runtime.getDeviceCount() will not work if xp = numpy

if gpu_enabled:
self._num_gpus = xp.cuda.runtime.getDeviceCount()
_id = httomo.globals.gpu_id
self._gpu_id = mpiutil.local_rank % self._num_gpus if _id == -1 else _id

  1. using xp.cuda.Event() will not work if xp = numpy

httomo/httomo/utils.py

Lines 271 to 276 in b28c2c3

class catch_gputime:
def __enter__(self):
if gpu_enabled:
self.start = xp.cuda.Event()
self.start.record()
return self

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions