Skip to content

Commit

Permalink
Add option for choosing device from python
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaldu committed Dec 20, 2023
1 parent 2a378f6 commit a25a533
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 30 deletions.
10 changes: 7 additions & 3 deletions CLUEstering/alpaka/BindingModules/CLUEstering.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ def list_devices(self, backend: str = "all") -> None:
def run_clue(self,
backend: str = "cpu serial",
block_size: int = 1024,
device_id: int = 0,
verbose: bool = False) -> None:
"""
Executes the CLUE clustering algorithm.
Expand Down Expand Up @@ -542,15 +543,18 @@ def run_clue(self,
if backend == "cpu serial":
cluster_id_is_seed = cpu_serial.mainRun(self.dc_, self.rhoc, self.outlier, self.ppbin,
self.clust_data.coords, self.clust_data.weight,
self.kernel, self.clust_data.n_dim, block_size)
self.kernel, self.clust_data.n_dim, block_size,
device_id)
elif backend == "cpu tbb":
cluster_id_is_seed = cpu_serial.mainRun(self.dc_, self.rhoc, self.outlier, self.ppbin,
self.clust_data.coords, self.clust_data.weight,
self.kernel, self.clust_data.n_dim, block_size)
self.kernel, self.clust_data.n_dim, block_size,
device_id)
elif backend == "gpu cuda":
cluster_id_is_seed = gpu_cuda.mainRun(self.dc_, float(self.rhoc), self.outlier, self.ppbin,
self.clust_data.coords, self.clust_data.weight,
self.kernel, self.clust_data.n_dim, block_size)
self.kernel, self.clust_data.n_dim, block_size,
device_id)
finish = time.time_ns()
cluster_ids = np.array(cluster_id_is_seed[0])
is_seed = np.array(cluster_id_is_seed[1])
Expand Down
24 changes: 15 additions & 9 deletions CLUEstering/alpaka/BindingModules/binding_cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ namespace alpaka_serial_sync {
const std::vector<float>& weights,
const FlatKernel& kernel,
int Ndim,
size_t block_size = 1024) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(0u);
size_t block_size,
size_t device_id) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(device_id);

// Create the queue
Queue queue_(dev_acc);
Expand Down Expand Up @@ -97,8 +98,9 @@ namespace alpaka_serial_sync {
const std::vector<float>& weights,
const ExponentialKernel& kernel,
int Ndim,
size_t block_size = 1024) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(0u);
size_t block_size,
size_t device_id) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(device_id);

// Create the queue
Queue queue_(dev_acc);
Expand Down Expand Up @@ -159,8 +161,9 @@ namespace alpaka_serial_sync {
const std::vector<float>& weights,
const GaussianKernel& kernel,
int Ndim,
size_t block_size) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(0u);
size_t block_size,
size_t device_id) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(device_id);

// Create the queue
Queue queue_(dev_acc);
Expand Down Expand Up @@ -226,7 +229,8 @@ namespace alpaka_serial_sync {
const std::vector<float>&,
const FlatKernel&,
int,
size_t>(&mainRun),
size_t,
size_t>(&mainRun),
"mainRun");
m.def("mainRun",
pybind11::overload_cast<float,
Expand All @@ -237,7 +241,8 @@ namespace alpaka_serial_sync {
const std::vector<float>&,
const ExponentialKernel&,
int,
size_t>(&mainRun),
size_t,
size_t>(&mainRun),
"mainRun");
m.def("mainRun",
pybind11::overload_cast<float,
Expand All @@ -248,7 +253,8 @@ namespace alpaka_serial_sync {
const std::vector<float>&,
const GaussianKernel&,
int,
size_t>(&mainRun),
size_t,
size_t>(&mainRun),
"mainRun");
}
}; // namespace alpaka_serial_sync
24 changes: 15 additions & 9 deletions CLUEstering/alpaka/BindingModules/binding_cpu_tbb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ namespace alpaka_tbb_async {
const std::vector<float>& weights,
const FlatKernel& kernel,
int Ndim,
size_t block_size) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(0u);
size_t block_size,
size_t device_id) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(device_id);

// Create the queue
Queue queue_(dev_acc);
Expand Down Expand Up @@ -97,8 +98,9 @@ namespace alpaka_tbb_async {
const std::vector<float>& weights,
const ExponentialKernel& kernel,
int Ndim,
size_t block_size) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(0u);
size_t block_size,
size_t device_id) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(device_id);

// Create the queue
Queue queue_(dev_acc);
Expand Down Expand Up @@ -159,8 +161,9 @@ namespace alpaka_tbb_async {
const std::vector<float>& weights,
const GaussianKernel& kernel,
int Ndim,
size_t block_size) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(0u);
size_t block_size,
size_t device_id) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(device_id);

// Create the queue
Queue queue_(dev_acc);
Expand Down Expand Up @@ -240,7 +243,8 @@ namespace alpaka_tbb_async {
const std::vector<float>&,
const FlatKernel&,
int,
size_t>(&mainRun),
size_t,
size_t>(&mainRun),
"mainRun");
m.def("mainRun",
pybind11::overload_cast<float,
Expand All @@ -251,7 +255,8 @@ namespace alpaka_tbb_async {
const std::vector<float>&,
const ExponentialKernel&,
int,
size_t>(&mainRun),
size_t,
size_t>(&mainRun),
"mainRun");
m.def("mainRun",
pybind11::overload_cast<float,
Expand All @@ -262,7 +267,8 @@ namespace alpaka_tbb_async {
const std::vector<float>&,
const GaussianKernel&,
int,
size_t>(&mainRun),
size_t,
size_t>(&mainRun),
"mainRun");

/* m.def("mainRun", &mainRun, "mainRun"); */
Expand Down
24 changes: 15 additions & 9 deletions CLUEstering/alpaka/BindingModules/binding_gpu_cuda.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ namespace alpaka_cuda_async {
const std::vector<float>& weights,
const FlatKernel& kernel,
int Ndim,
size_t block_size) {
size_t block_size,
size_t device_id) {
std::vector<Device> devices = alpaka::getDevs<Platform>();

auto const dev_acc = alpaka::getDevByIdx<Acc1D>(0u);
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(device_id);

/* initialise<Platform>(); */

Expand Down Expand Up @@ -103,8 +104,9 @@ namespace alpaka_cuda_async {
const std::vector<float>& weights,
const ExponentialKernel& kernel,
int Ndim,
size_t block_size) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(0u);
size_t block_size,
size_t device_id) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(device_id);

// Create the queue
Queue queue_(dev_acc);
Expand Down Expand Up @@ -165,8 +167,9 @@ namespace alpaka_cuda_async {
const std::vector<float>& weights,
const GaussianKernel& kernel,
int Ndim,
size_t block_size) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(0u);
size_t block_size,
size_t device_id) {
auto const dev_acc = alpaka::getDevByIdx<Acc1D>(device_id);

// Create the queue
Queue queue_(dev_acc);
Expand Down Expand Up @@ -232,7 +235,8 @@ namespace alpaka_cuda_async {
const std::vector<float>&,
const FlatKernel&,
int,
size_t>(&mainRun),
size_t,
size_t>(&mainRun),
"mainRun");
m.def("mainRun",
pybind11::overload_cast<float,
Expand All @@ -243,7 +247,8 @@ namespace alpaka_cuda_async {
const std::vector<float>&,
const ExponentialKernel&,
int,
size_t>(&mainRun),
size_t,
size_t>(&mainRun),
"mainRun");
m.def("mainRun",
pybind11::overload_cast<float,
Expand All @@ -254,7 +259,8 @@ namespace alpaka_cuda_async {
const std::vector<float>&,
const GaussianKernel&,
int,
size_t>(&mainRun),
size_t,
size_t>(&mainRun),
"mainRun");
}
}; // namespace alpaka_cuda_async

0 comments on commit a25a533

Please sign in to comment.