model-layer/scalable-tf-module/FTcom/util.cpp
/* Create the (N-1)-order permutation table for efficient access to the set of subtensors  */
Create the (N-1)-order permutation table for efficient access to the set of subtensors
Create the ( N - 1 ) - order permutation table for efficient access to the set of subtensors
void Precompute_Permutation(int **&gridPermu) {
	int i, k;
	int gridSize = Option::gridSize;
	int order = Option::tensorOrder;
	int partTensors_N = pow(gridSize, order-1);
	gridPermu = (int **)malloc(sizeof(int *)*partTensors_N);
	gridPermu[0] = (int *)malloc(sizeof(int)*partTensors_N*(order-1));
	memset(gridPermu[0], 0, sizeof(int)*(order-1));
	for (i = 1; i < partTensors_N; i++) {
		gridPermu[i] = &gridPermu[0][i*(order-1)];
		memcpy(gridPermu[i], gridPermu[i-1], sizeof(int)*(order-1));
		k = order-2;
		gridPermu[i][k]++;
		while (gridPermu[i][k] >= gridSize) {
			gridPermu[i][k] -= gridSize;
			gridPermu[i][k-1]++;
			k--;
		}
	}
}
void Precompute_Permutation ( int * * & gridPermu ) { int i , k ; int gridSize = Option :: gridSize ; int order = Option :: tensorOrder ; int partTensors_N = pow ( gridSize , order - 1 ) ; gridPermu = ( int * * ) malloc ( sizeof ( int * ) * partTensors_N ) ; gridPermu [ 0 ] = ( int * ) malloc ( sizeof ( int ) * partTensors_N * ( order - 1 ) ) ; memset ( gridPermu [ 0 ] , 0 , sizeof ( int ) * ( order - 1 ) ) ; for ( i = 1 ; i < partTensors_N ; i ++ ) { gridPermu [ i ] = & gridPermu [ 0 ] [ i * ( order - 1 ) ] ; memcpy ( gridPermu [ i ] , gridPermu [ i - 1 ] , sizeof ( int ) * ( order - 1 ) ) ; k = order - 2 ; gridPermu [ i ] [ k ] ++ ; while ( gridPermu [ i ] [ k ] >= gridSize ) { gridPermu [ i ] [ k ] -= gridSize ; gridPermu [ i ] [ k - 1 ] ++ ; k -- ; } } }
Create the (N-1)-order permutation table for efficient access to the set of subtensors
Create the ( N - 1 ) - order permutation table for efficient access to the set of subtensors