Skip to content

Commit

Permalink
Move ttg::device in the top of the hierarchy, rename functions to be …
Browse files Browse the repository at this point in the history
…more explicit.
  • Loading branch information
therault committed Mar 13, 2023
1 parent 33134dc commit 3c08678
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
15 changes: 15 additions & 0 deletions ttg/ttg/device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef TTG_DEVICE_H
#define TTG_DEVICE_H

#include "ttg/fwd.h"

namespace ttg {
namespace device {
std::size_t get_nb() { return TTG_IMPL_NS::device::get_nb(); }
void *memory_allocate(int did, std::size_t size) { return TTG_IMPL_NS::device::memory_allocate(did, size); }
void memory_free(int did, void *p) { TTG_IMPL_NS::device::memory_free(did, p); }
ttg::ExecutionSpace execution_space(int did) { return TTG_IMPL_NS::device::execution_space(did); }
}
}

#endif /* TTG_DEVICE_H */
8 changes: 4 additions & 4 deletions ttg/ttg/madness/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ namespace ttg_madness {
inline void ttg_broadcast(ttg::World world, T &data, int source_rank);

namespace device {
std::size_t nb();
void *allocate(int did, std::size_t size);
void free(int did, void *ptr);
ttg::ExecutionSpace space(int did);
std::size_t get_nb();
void *memory_allocate(int did, std::size_t size);
void memory_free(int did, void *ptr);
ttg::ExecutionSpace execution_space(int did);
}

} // namespace ttg_madness
Expand Down
8 changes: 4 additions & 4 deletions ttg/ttg/madness/ttg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1278,20 +1278,20 @@ namespace ttg_madness {
#include "ttg/make_tt.h"

namespace device {
std::size_t nb() { return 1; }
void *allocate(int did, std::size_t size) {
std::size_t get_nb() { return 1; }
void *memory_allocate(int did, std::size_t size) {
if(did != 0) {
throw std::out_of_range("TTG MADNESS Backend does not support other devices than CPU at this time");
}
return ::malloc(size);
}
void free(int did, void *ptr) {
void memory_free(int did, void *ptr) {
if(did != 0) {
throw std::out_of_range("TTG MADNESS Backend does not support other devices than CPU at this time");
}
::free(ptr);
}
ttg::ExecutionSpace space(int did) {
ttg::ExecutionSpace execution_space(int did) {
if(did != 0) {
throw std::out_of_range("TTG MADNESS Backend does not support other devices than CPU at this time");
}
Expand Down
14 changes: 7 additions & 7 deletions ttg/ttg/parsec/ttg.h
Original file line number Diff line number Diff line change
Expand Up @@ -3490,7 +3490,7 @@ namespace ttg_parsec {
static int *ttg_devid;
}

std::size_t nb() {
std::size_t get_nb() {
if(0 != detail::nb_ttg_devices) return detail::nb_ttg_devices;
detail::ttg_devid = new int[parsec_nb_devices];
for(int i = 0; i < parsec_nb_devices; i++) {
Expand All @@ -3511,8 +3511,8 @@ namespace ttg_parsec {
return detail::nb_ttg_devices;
}

void *allocate(int did, std::size_t size) {
if(did >= nb()) {
void *memory_allocate(int did, std::size_t size) {
if(did >= get_nb()) {
throw std::out_of_range("TTG PaRSEC - device identifier out of range");
}
if(0 == did)
Expand All @@ -3525,8 +3525,8 @@ namespace ttg_parsec {
return zone_malloc(gm->memory, size);
}

void free(int did, void *ptr) {
if(did >= nb()) {
void memory_free(int did, void *ptr) {
if(did >= get_nb()) {
throw std::out_of_range("TTG PaRSEC - device identifier out of range");
}
if(0 == did) {
Expand All @@ -3540,8 +3540,8 @@ namespace ttg_parsec {
zone_free(gm->memory, ptr);
}

ttg::ExecutionSpace space(int did) {
if(did >= nb()) {
ttg::ExecutionSpace execution_space(int did) {
if(did >= get_nb()) {
throw std::out_of_range("TTG PaRSEC - device identifier out of range");
}
if(0 == did) {
Expand Down
13 changes: 0 additions & 13 deletions ttg/ttg/util/device.h

This file was deleted.

0 comments on commit 3c08678

Please sign in to comment.