Skip to content

Commit

Permalink
clone(DistArray) supports device-based arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
evaleev committed Sep 28, 2023
1 parent 089dcc6 commit c612b71
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/TiledArray/conversions/clone.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#ifndef TILEDARRAY_CONVERSIONS_CLONE_H__INCLUDED
#define TILEDARRAY_CONVERSIONS_CLONE_H__INCLUDED

#ifdef TILEDARRAY_HAS_DEVICE
#include "TiledArray/device/device_task_fn.h"
#endif

namespace TiledArray {

/// Forward declarations
Expand Down Expand Up @@ -53,12 +57,28 @@ inline DistArray<Tile, Policy> clone(const DistArray<Tile, Policy>& arg) {
if (arg.is_zero(index)) continue;

// Spawn a task to clone the tiles
Future<value_type> tile = world.taskq.add(
[](const value_type& tile) -> value_type {
using TiledArray::clone;
return clone(tile);
},
arg.find(index));

Future<value_type> tile;
if constexpr (!detail::is_device_tile_v<value_type>) {
tile = world.taskq.add(
[](const value_type& tile) -> value_type {
using TiledArray::clone;
return clone(tile);
},
arg.find(index));
} else {
#ifdef TILEDARRAY_HAS_DEVICE
tile = madness::add_device_task(
world,
[](const value_type& tile) -> value_type {
using TiledArray::clone;
return clone(tile);
},
arg.find(index));
#else
abort(); // unreachable
#endif
}

// Store result tile
result.set(index, tile);
Expand Down

0 comments on commit c612b71

Please sign in to comment.