src/tiramisu_core.cpp
void computation::split(int L0, int sizeX)
{
    DEBUG_FCT_NAME(3);
    DEBUG_INDENT(4);

    int inDim0 = loop_level_into_dynamic_dimension(L0);

    assert(this->get_schedule() != NULL);
    assert(inDim0 >= 0);
    assert(inDim0 < isl_space_dim(isl_map_get_space(this->get_schedule()), isl_dim_out));
    assert(sizeX >= 1);

    isl_map *schedule = this->get_schedule();
    int duplicate_ID = isl_map_get_static_dim(schedule, 0);

    schedule = isl_map_copy(schedule);
    schedule = isl_map_set_tuple_id(schedule, isl_dim_out,
                                    isl_id_alloc(this->get_ctx(), this->get_name().c_str(), NULL));


    DEBUG(3, tiramisu::str_dump("Original schedule: ", isl_map_to_str(schedule)));
    DEBUG(3, tiramisu::str_dump("Splitting dimension " + std::to_string(inDim0)
                                + " with split size " + std::to_string(sizeX)));

    std::string inDim0_str;

    std::string outDim0_str = generate_new_variable_name();
    std::string static_dim_str = generate_new_variable_name();
    std::string outDim1_str = generate_new_variable_name();

    int n_dims = isl_map_dim(this->get_schedule(), isl_dim_out);
    std::vector<isl_id *> dimensions;
    std::vector<std::string> dimensions_str;
    std::string map = "{";

    // -----------------------------------------------------------------
    // Preparing a map to split the duplicate computation.
    // -----------------------------------------------------------------

    map = map + this->get_name() + "[";

    for (int i = 0; i < n_dims; i++)
    {
        if (i == 0)
        {
            std::string dim_str = generate_new_variable_name();
            dimensions_str.push_back(dim_str);
            map = map + dim_str;
        }
        else
        {
            std::string dim_str = generate_new_variable_name();
            dimensions_str.push_back(dim_str);
            map = map + dim_str;

            if (i == inDim0)
            {
                inDim0_str = dim_str;
            }
        }

        if (i != n_dims - 1)
        {
            map = map + ",";
        }
    }

    map = map + "] -> " + this->get_name() + "[";

    for (int i = 0; i < n_dims; i++)
    {
        if (i == 0)
        {
            map = map + dimensions_str[i];
            dimensions.push_back(isl_id_alloc(
                                     this->get_ctx(),
                                     dimensions_str[i].c_str(),
                                     NULL));
        }
        else if (i != inDim0)
        {
            map = map + dimensions_str[i];
            dimensions.push_back(isl_id_alloc(
                                     this->get_ctx(),
                                     dimensions_str[i].c_str(),
                                     NULL));
        }
        else
        {
            map = map + outDim0_str + ", " + static_dim_str + ", " + outDim1_str;
            isl_id *id0 = isl_id_alloc(this->get_ctx(),
                                       outDim0_str.c_str(), NULL);
            isl_id *id2 = isl_id_alloc(this->get_ctx(),
                                       static_dim_str.c_str(), NULL);
            isl_id *id1 = isl_id_alloc(this->get_ctx(),
                                       outDim1_str.c_str(), NULL);
            dimensions.push_back(id0);
            dimensions.push_back(id2);
            dimensions.push_back(id1);
        }

        if (i != n_dims - 1)
        {
            map = map + ",";
        }
    }

    map = map + "] : " + dimensions_str[0] + " = " + std::to_string(duplicate_ID) + " and " +
          outDim0_str + " = floor(" + inDim0_str + "/" +
          std::to_string(sizeX) + ") and " + outDim1_str + " = (" +
          inDim0_str + "%" + std::to_string(sizeX) + ") and " + static_dim_str + " = 0}";

    isl_map *transformation_map = isl_map_read_from_str(this->get_ctx(), map.c_str());

    for (int i = 0; i < dimensions.size(); i++)
        transformation_map = isl_map_set_dim_id(
                                 transformation_map, isl_dim_out, i, isl_id_copy(dimensions[i]));

    transformation_map = isl_map_set_tuple_id(
                             transformation_map, isl_dim_in,
                             isl_map_get_tuple_id(isl_map_copy(schedule), isl_dim_out));
    isl_id *id_range = isl_id_alloc(this->get_ctx(), this->get_name().c_str(), NULL);
    transformation_map = isl_map_set_tuple_id(transformation_map, isl_dim_out, id_range);

    DEBUG(3, tiramisu::str_dump("Transformation map : ",
                                isl_map_to_str(transformation_map)));

    schedule = isl_map_apply_range(isl_map_copy(schedule), isl_map_copy(transformation_map));

    DEBUG(3, tiramisu::str_dump("Schedule after splitting: ", isl_map_to_str(schedule)));

    this->set_schedule(schedule);

    DEBUG_INDENT(-4);
}
/**
 * Modify the schedule of this computation so that it splits the
 * loop level L0 into two new loop levels.
 * The size of the inner dimension created is sizeX.
 */
Modify the schedule of this computation so that it splits the
loop level L0 into two new loop levels.
The size of the inner dimension created is sizeX.
Modify the schedule of this computation so that it splits the loop level L0 into two new loop levels . The size of the inner dimension created is sizeX .
void computation::split(int L0, int sizeX)
{
    DEBUG_FCT_NAME(3);
    DEBUG_INDENT(4);
    int inDim0 = loop_level_into_dynamic_dimension(L0);
    assert(this->get_schedule() != NULL);
    assert(inDim0 >= 0);
    assert(inDim0 < isl_space_dim(isl_map_get_space(this->get_schedule()), isl_dim_out));
    assert(sizeX >= 1);
    isl_map *schedule = this->get_schedule();
    int duplicate_ID = isl_map_get_static_dim(schedule, 0);
    schedule = isl_map_copy(schedule);
    schedule = isl_map_set_tuple_id(schedule, isl_dim_out,
                                    isl_id_alloc(this->get_ctx(), this->get_name().c_str(), NULL));
    DEBUG(3, tiramisu::str_dump("Original schedule: ", isl_map_to_str(schedule)));
    DEBUG(3, tiramisu::str_dump("Splitting dimension " + std::to_string(inDim0)
                                + " with split size " + std::to_string(sizeX)));
    std::string inDim0_str;
    std::string outDim0_str = generate_new_variable_name();
    std::string static_dim_str = generate_new_variable_name();
    std::string outDim1_str = generate_new_variable_name();
    int n_dims = isl_map_dim(this->get_schedule(), isl_dim_out);
    std::vector<isl_id *> dimensions;
    std::vector<std::string> dimensions_str;
    std::string map = "{";
    map = map + this->get_name() + "[";
    for (int i = 0; i < n_dims; i++)
    {
        if (i == 0)
        {
            std::string dim_str = generate_new_variable_name();
            dimensions_str.push_back(dim_str);
            map = map + dim_str;
        }
        else
        {
            std::string dim_str = generate_new_variable_name();
            dimensions_str.push_back(dim_str);
            map = map + dim_str;
            if (i == inDim0)
            {
                inDim0_str = dim_str;
            }
        }
        if (i != n_dims - 1)
        {
            map = map + ",";
        }
    }
    map = map + "] -> " + this->get_name() + "[";
    for (int i = 0; i < n_dims; i++)
    {
        if (i == 0)
        {
            map = map + dimensions_str[i];
            dimensions.push_back(isl_id_alloc(
                                     this->get_ctx(),
                                     dimensions_str[i].c_str(),
                                     NULL));
        }
        else if (i != inDim0)
        {
            map = map + dimensions_str[i];
            dimensions.push_back(isl_id_alloc(
                                     this->get_ctx(),
                                     dimensions_str[i].c_str(),
                                     NULL));
        }
        else
        {
            map = map + outDim0_str + ", " + static_dim_str + ", " + outDim1_str;
            isl_id *id0 = isl_id_alloc(this->get_ctx(),
                                       outDim0_str.c_str(), NULL);
            isl_id *id2 = isl_id_alloc(this->get_ctx(),
                                       static_dim_str.c_str(), NULL);
            isl_id *id1 = isl_id_alloc(this->get_ctx(),
                                       outDim1_str.c_str(), NULL);
            dimensions.push_back(id0);
            dimensions.push_back(id2);
            dimensions.push_back(id1);
        }
        if (i != n_dims - 1)
        {
            map = map + ",";
        }
    }
    map = map + "] : " + dimensions_str[0] + " = " + std::to_string(duplicate_ID) + " and " +
          outDim0_str + " = floor(" + inDim0_str + "/" +
          std::to_string(sizeX) + ") and " + outDim1_str + " = (" +
          inDim0_str + "%" + std::to_string(sizeX) + ") and " + static_dim_str + " = 0}";
    isl_map *transformation_map = isl_map_read_from_str(this->get_ctx(), map.c_str());
    for (int i = 0; i < dimensions.size(); i++)
        transformation_map = isl_map_set_dim_id(
                                 transformation_map, isl_dim_out, i, isl_id_copy(dimensions[i]));
    transformation_map = isl_map_set_tuple_id(
                             transformation_map, isl_dim_in,
                             isl_map_get_tuple_id(isl_map_copy(schedule), isl_dim_out));
    isl_id *id_range = isl_id_alloc(this->get_ctx(), this->get_name().c_str(), NULL);
    transformation_map = isl_map_set_tuple_id(transformation_map, isl_dim_out, id_range);
    DEBUG(3, tiramisu::str_dump("Transformation map : ",
                                isl_map_to_str(transformation_map)));
    schedule = isl_map_apply_range(isl_map_copy(schedule), isl_map_copy(transformation_map));
    DEBUG(3, tiramisu::str_dump("Schedule after splitting: ", isl_map_to_str(schedule)));
    this->set_schedule(schedule);
    DEBUG_INDENT(-4);
}
void computation :: split ( int L0 , int sizeX ) { DEBUG_FCT_NAME ( 3 ) ; DEBUG_INDENT ( 4 ) ; int inDim0 = loop_level_into_dynamic_dimension ( L0 ) ; assert ( this -> get_schedule ( ) != NULL ) ; assert ( inDim0 >= 0 ) ; assert ( inDim0 < isl_space_dim ( isl_map_get_space ( this -> get_schedule ( ) ) , isl_dim_out ) ) ; assert ( sizeX >= 1 ) ; isl_map * schedule = this -> get_schedule ( ) ; int duplicate_ID = isl_map_get_static_dim ( schedule , 0 ) ; schedule = isl_map_copy ( schedule ) ; schedule = isl_map_set_tuple_id ( schedule , isl_dim_out , isl_id_alloc ( this -> get_ctx ( ) , this -> get_name ( ) . c_str ( ) , NULL ) ) ; DEBUG ( 3 , tiramisu :: str_dump ( " " , isl_map_to_str ( schedule ) ) ) ; DEBUG ( 3 , tiramisu :: str_dump ( " " + std :: to_string ( inDim0 ) + " " + std :: to_string ( sizeX ) ) ) ; std :: string inDim0_str ; std :: string outDim0_str = generate_new_variable_name ( ) ; std :: string static_dim_str = generate_new_variable_name ( ) ; std :: string outDim1_str = generate_new_variable_name ( ) ; int n_dims = isl_map_dim ( this -> get_schedule ( ) , isl_dim_out ) ; std :: vector < isl_id * > dimensions ; std :: vector < std :: string > dimensions_str ; std :: string map = " " ; map = map + this -> get_name ( ) + " " ; for ( int i = 0 ; i < n_dims ; i ++ ) { if ( i == 0 ) { std :: string dim_str = generate_new_variable_name ( ) ; dimensions_str . push_back ( dim_str ) ; map = map + dim_str ; } else { std :: string dim_str = generate_new_variable_name ( ) ; dimensions_str . push_back ( dim_str ) ; map = map + dim_str ; if ( i == inDim0 ) { inDim0_str = dim_str ; } } if ( i != n_dims - 1 ) { map = map + " " ; } } map = map + " " + this -> get_name ( ) + " " ; for ( int i = 0 ; i < n_dims ; i ++ ) { if ( i == 0 ) { map = map + dimensions_str [ i ] ; dimensions . push_back ( isl_id_alloc ( this -> get_ctx ( ) , dimensions_str [ i ] . c_str ( ) , NULL ) ) ; } else if ( i != inDim0 ) { map = map + dimensions_str [ i ] ; dimensions . push_back ( isl_id_alloc ( this -> get_ctx ( ) , dimensions_str [ i ] . c_str ( ) , NULL ) ) ; } else { map = map + outDim0_str + " " + static_dim_str + " " + outDim1_str ; isl_id * id0 = isl_id_alloc ( this -> get_ctx ( ) , outDim0_str . c_str ( ) , NULL ) ; isl_id * id2 = isl_id_alloc ( this -> get_ctx ( ) , static_dim_str . c_str ( ) , NULL ) ; isl_id * id1 = isl_id_alloc ( this -> get_ctx ( ) , outDim1_str . c_str ( ) , NULL ) ; dimensions . push_back ( id0 ) ; dimensions . push_back ( id2 ) ; dimensions . push_back ( id1 ) ; } if ( i != n_dims - 1 ) { map = map + " " ; } } map = map + " " + dimensions_str [ 0 ] + " " + std :: to_string ( duplicate_ID ) + " " + outDim0_str + " " + inDim0_str + " " + std :: to_string ( sizeX ) + " " + outDim1_str + " " + inDim0_str + " " + std :: to_string ( sizeX ) + " " + static_dim_str + " " ; isl_map * transformation_map = isl_map_read_from_str ( this -> get_ctx ( ) , map . c_str ( ) ) ; for ( int i = 0 ; i < dimensions . size ( ) ; i ++ ) transformation_map = isl_map_set_dim_id ( transformation_map , isl_dim_out , i , isl_id_copy ( dimensions [ i ] ) ) ; transformation_map = isl_map_set_tuple_id ( transformation_map , isl_dim_in , isl_map_get_tuple_id ( isl_map_copy ( schedule ) , isl_dim_out ) ) ; isl_id * id_range = isl_id_alloc ( this -> get_ctx ( ) , this -> get_name ( ) . c_str ( ) , NULL ) ; transformation_map = isl_map_set_tuple_id ( transformation_map , isl_dim_out , id_range ) ; DEBUG ( 3 , tiramisu :: str_dump ( " " , isl_map_to_str ( transformation_map ) ) ) ; schedule = isl_map_apply_range ( isl_map_copy ( schedule ) , isl_map_copy ( transformation_map ) ) ; DEBUG ( 3 , tiramisu :: str_dump ( " " , isl_map_to_str ( schedule ) ) ) ; this -> set_schedule ( schedule ) ; DEBUG_INDENT ( -4 ) ; }
Modify the schedule of this computation so that it splits the
 loop level L0 into two new loop levels.
Modify the schedule of this computation so that it splits the loop level L0 into two new loop levels .
// ----------------------------------------------------------------- // Preparing a map to split the duplicate computation. // -----------------------------------------------------------------