Skip to content

Commit 0b45c49

Browse files
committed
add memory control for desymmetrization, and an early check on max_nvirt to avoid overflow. Max desymmetrization size for skew symmetric or symmetric hollow tensors can now be bounded in bytes by the environment variable CTF_MAX_DESYM_SIZE.
1 parent c3f9582 commit 0b45c49

File tree

8 files changed

+186
-117
lines changed

8 files changed

+186
-117
lines changed

src/contraction/contraction.cxx

Lines changed: 139 additions & 104 deletions
Large diffs are not rendered by default.

src/contraction/contraction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ namespace CTF_int {
362362
* \brief returns true if prescale_operands has real work to do
363363
*/
364364
bool need_prescale_operands();
365+
366+
/**
367+
* \brief returns true if tensors are small enough to desymmetrize
368+
*/
369+
bool is_ok_to_to_desym();
365370
};
366371

367372
class contraction_signature {

src/interface/world.cxx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ namespace CTF {
208208

209209
int World::initialize(int argc,
210210
const char * const * argv){
211-
char * mem_size, * cppn;
211+
char * mem_size, * max_desym_size, * cppn;
212212
if (comm == MPI_COMM_WORLD && universe_exists){
213213
delete phys_topology;
214214
*this = universe;
@@ -274,15 +274,29 @@ namespace CTF {
274274
coeff_file = std::string(file_path);
275275
CTF_int::load_all_models(coeff_file);
276276
}
277-
277+
int64_t imem_size = 0;
278278
mem_size = getenv("CTF_MEMORY_SIZE");
279279
if (mem_size != NULL){
280-
int64_t imem_size = strtoull(mem_size,NULL,0);
280+
imem_size = strtoull(mem_size,NULL,0);
281281
if (rank == 0)
282282
VPRINTF(1,"Memory size set to %ld by CTF_MEMORY_SIZE environment variable\n",
283283
imem_size);
284284
CTF_int::set_mem_size(imem_size);
285285
}
286+
287+
288+
max_desym_size = getenv("CTF_MAX_DESYM_SIZE");
289+
if (max_desym_size != NULL){
290+
int64_t imax_desym_size = strtoull(max_desym_size,NULL,0);
291+
if (rank == 0)
292+
VPRINTF(1,"Max desymmetrization tensor size set to %ld by CTF_AX_DESYM_SIZE environment variable\n",
293+
imax_desym_size);
294+
CTF_int::set_max_desym_size(imax_desym_size);
295+
} else if (imem_size != 0) {
296+
CTF_int::set_max_desym_size(imem_size/6);
297+
}
298+
299+
286300
cppn = getenv("CTF_PPN");
287301
if (cppn != NULL){
288302
int icppn = atoi(cppn);

src/shared/memcontrol.cxx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace CTF_int {
4747
/* fraction of total memory which can be saturated */
4848
double memcap = 0.5;
4949
int64_t mem_size = 0;
50+
int64_t max_desym_size = 0;
5051
#define MAX_THREADS 256
5152
int max_threads;
5253
int instance_counter = 0;
@@ -81,6 +82,21 @@ namespace CTF_int {
8182
mem_size = size;
8283
}
8384

85+
/**
86+
* \brief sets a limit on size of tensor which CTF will desymmetrize during contraction
87+
*/
88+
void set_max_desym_size(int64_t size){
89+
max_desym_size = size;
90+
}
91+
92+
/**
93+
* \brief gets limit on size of tensor which CTF will desymmetrize during contraction
94+
*/
95+
int64_t get_max_desym_size(){
96+
return max_desym_size;
97+
}
98+
99+
84100
/**
85101
* \brief sets what fraction of the memory capacity CTF can use
86102
* \param[in] cap memory fraction

src/shared/memcontrol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace CTF_int {
1111
int64_t proc_bytes_available();
1212
void set_memcap(double cap);
1313
void set_mem_size(int64_t size);
14+
void set_max_desym_size(int64_t size);
15+
int64_t get_max_desym_size();
1416
int get_num_instances();
1517
void start_memprof(int rank);
1618
void stop_memprof();

src/shared/util.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,8 @@ namespace CTF_int {
6363
#include "fompi_wrapper.h"
6464

6565
namespace CTF_int {
66-
//max total virtualization factor for mappings
67-
#define MAX_NVIRT 256
68-
//min total virtualization factor for mappings
69-
// (would be useful if explicit blockwise threading was enabled, which is not currently)
70-
#ifndef MIN_NVIRT
71-
#define MIN_NVIRT 1
66+
#ifndef MAX_NVIRT
67+
#define MAX_NVIRT 5000
7268
#endif
7369

7470
#ifndef ENABLE_ASSERT

src/tensor/untyped_tensor.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3948,10 +3948,10 @@ namespace CTF_int {
39483948
delete func;
39493949
}
39503950

3951-
bool tensor::has_symmetry() const {
3951+
bool tensor::has_symmetry(int sym_type) const {
39523952
bool is_nonsym=true;
39533953
for (int i=0; i<order; i++){
3954-
if (sym[i] != NS){
3954+
if ((sym_type == -1 && sym[i] != NS) || (sym_type != -1 && sym[i] == sym_type)){
39553955
is_nonsym = false;
39563956
}
39573957
}

src/tensor/untyped_tensor.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,9 +1042,10 @@ namespace CTF_int {
10421042

10431043
/**
10441044
* \brief checks if there is any symmetry defined as part of sym
1045-
* \return true if sym[i] != NS for some i
1045+
* \param[in] sym_type type of symmetry to check for
1046+
* \return true if sym_type = -1 and sym[i] != NS for some i or if sym[i] = sym_type
10461047
*/
1047-
bool has_symmetry() const;
1048+
bool has_symmetry(int sym_type=-1) const;
10481049

10491050

10501051
/**

0 commit comments

Comments
 (0)