<commit_before>/* Copyright 2015 Stanford University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#include <map>
#include <set>

#include "default_mapper.h"
#include "ebb_mapper.h"
#include "serialize.h"

using namespace LegionRuntime::HighLevel;

// legion logger
LegionRuntime::Logger::Category log_mapper("mapper");

// message types
enum MapperMessageType {
  MAPPER_RECORD_FIELD,
  MAPPER_TOTAL_MESSAGES
};

class EbbMapper : public DefaultMapper {
public:
  EbbMapper(Machine machine, HighLevelRuntime *rt, Processor local);
  virtual void select_task_options(Task *task);
  virtual bool pre_map_task(Task *task);
  virtual bool map_task(Task *task);
  virtual bool map_inline(Inline *inline_operation);
  virtual void notify_mapping_failed(const Mappable *mappable);
  virtual bool rank_copy_targets(const Mappable *mappable,
                                 LogicalRegion rebuild_region,
                                 const std::set<Memory> &current_instances,
                                 bool complete,
                                 size_t max_blocking_factor,
                                 std::set<Memory> &to_reuse,
                                 std::vector<Memory> &to_create,
                                 bool &create_one,
                                 size_t &blocking_factor);
  virtual void handle_message(Processor source,
                              const void *message, size_t length);
private:
  // active fields for a logical region
  std::map<std::string, std::set<FieldID> > active_fields;
  // get logical region corresponding to a region requirement
  LogicalRegion get_logical_region(const RegionRequirement &req);
  LogicalRegion get_root_region(const LogicalRegion &handle);
  LogicalRegion get_root_region(const LogicalPartition &handle);
};  // class EbbMapper

// EbbMapper constructor
EbbMapper::EbbMapper(Machine machine, HighLevelRuntime *rt, Processor local)
  : DefaultMapper(machine, rt, local) {
}

LogicalRegion EbbMapper::get_logical_region(const RegionRequirement &req) {
  LogicalRegion root;
  if (req.handle_type == SINGULAR || req.handle_type == REG_PROJECTION) {
    root = get_root_region(req.region);
  } else {
    assert(req.handle_type == PART_PROJECTION);
    root = get_root_region(req.partition);
  }
  return root;
}

LogicalRegion EbbMapper::get_root_region(const LogicalRegion &handle) {
  if (has_parent_logical_partition(handle)) {
    return get_root_region(get_parent_logical_partition(handle));
  }
  return handle;
}

LogicalRegion EbbMapper::get_root_region(const LogicalPartition &handle) {
  return get_root_region(get_parent_logical_region(handle));
}

void EbbMapper::select_task_options(Task *task) {
  DefaultMapper::select_task_options(task);
}

bool EbbMapper::pre_map_task(Task *task) {
  std::vector<RegionRequirement> &regions = task->regions;
  for (std::vector<RegionRequirement>::iterator it = regions.begin();
        it != regions.end(); it++) {
    RegionRequirement &req = *it;
    if (req.handle_type == SINGULAR) {
      req.must_early_map = true;
    }
  }

  bool success = DefaultMapper::pre_map_task(task);

  for (std::vector<RegionRequirement>::iterator it = regions.begin();
        it != regions.end(); it++) {
    RegionRequirement &req = *it;
    if (req.must_early_map && !req.redop) {
      LogicalRegion root = get_logical_region(req);
      const char *name_c;
      runtime->retrieve_name(root, name_c);
      std::string name(name_c);
      assert(active_fields.find(name) != active_fields.end());
      std::set<FieldID> &additional = active_fields[name];
      req.additional_fields.insert(additional.begin(),
                                   additional.end());
    }
  }

  return success;
}

bool EbbMapper::map_task(Task *task) {
  bool success = DefaultMapper::map_task(task);

  // add additional fields to region requirements
  std::vector<RegionRequirement> &regions = task->regions;
  for (std::vector<RegionRequirement>::iterator it = regions.begin();
        it != regions.end(); it++) {
    RegionRequirement &req = *it;
    if (!req.redop) {
        LogicalRegion root = get_logical_region(req);
        const char *name_c;
        runtime->retrieve_name(root, name_c);
        std::string name(name_c);
        assert(active_fields.find(name) != active_fields.end());
        std::set<FieldID> &additional = active_fields[name];
        req.additional_fields.insert(additional.begin(),
                                     additional.end());
    }
  }

  return success;<commit_msg>Avoid use of pre_map_task.<commit_after>/* Copyright 2015 Stanford University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#include <map>
#include <set>

#include "default_mapper.h"
#include "ebb_mapper.h"
#include "serialize.h"

using namespace LegionRuntime::HighLevel;

// legion logger
LegionRuntime::Logger::Category log_mapper("mapper");

// message types
enum MapperMessageType {
  MAPPER_RECORD_FIELD,
  MAPPER_TOTAL_MESSAGES
};

class EbbMapper : public DefaultMapper {
public:
  EbbMapper(Machine machine, HighLevelRuntime *rt, Processor local);
  virtual void select_task_options(Task *task);
  virtual bool map_task(Task *task);
  virtual bool map_inline(Inline *inline_operation);
  virtual void notify_mapping_failed(const Mappable *mappable);
  virtual bool rank_copy_targets(const Mappable *mappable,
                                 LogicalRegion rebuild_region,
                                 const std::set<Memory> &current_instances,
                                 bool complete,
                                 size_t max_blocking_factor,
                                 std::set<Memory> &to_reuse,
                                 std::vector<Memory> &to_create,
                                 bool &create_one,
                                 size_t &blocking_factor);
  virtual void handle_message(Processor source,
                              const void *message, size_t length);
private:
  // active fields for a logical region
  std::map<std::string, std::set<FieldID> > active_fields;
  // get logical region corresponding to a region requirement
  LogicalRegion get_logical_region(const RegionRequirement &req);
  LogicalRegion get_root_region(const LogicalRegion &handle);
  LogicalRegion get_root_region(const LogicalPartition &handle);
};  // class EbbMapper

// EbbMapper constructor
EbbMapper::EbbMapper(Machine machine, HighLevelRuntime *rt, Processor local)
  : DefaultMapper(machine, rt, local) {
}

LogicalRegion EbbMapper::get_logical_region(const RegionRequirement &req) {
  LogicalRegion root;
  if (req.handle_type == SINGULAR || req.handle_type == REG_PROJECTION) {
    root = get_root_region(req.region);
  } else {
    assert(req.handle_type == PART_PROJECTION);
    root = get_root_region(req.partition);
  }
  return root;
}

LogicalRegion EbbMapper::get_root_region(const LogicalRegion &handle) {
  if (has_parent_logical_partition(handle)) {
    return get_root_region(get_parent_logical_partition(handle));
  }
  return handle;
}

LogicalRegion EbbMapper::get_root_region(const LogicalPartition &handle) {
  return get_root_region(get_parent_logical_region(handle));
}

void EbbMapper::select_task_options(Task *task) {
  DefaultMapper::select_task_options(task);
}

bool EbbMapper::map_task(Task *task) {
  bool success = DefaultMapper::map_task(task);

  // add additional fields to region requirements
  std::vector<RegionRequirement> &regions = task->regions;
  for (std::vector<RegionRequirement>::iterator it = regions.begin();
        it != regions.end(); it++) {
    RegionRequirement &req = *it;
    if (!req.redop) {
        LogicalRegion root = get_logical_region(req);
        const char *name_c;
        runtime->retrieve_name(root, name_c);
        std::string name(name_c);
        assert(active_fields.find(name) != active_fields.end());
        std::set<FieldID> &additional = active_fields[name];
        req.additional_fields.insert(additional.begin(),
                                     additional.end());
    }
  }

  return success;
{'fraction_non_alphanumeric': 0.09976874793524942, 'fraction_numerical': 0.0017619204933377382, 'mean_word_length': 3.341300191204589, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 19, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7620584', 'n_tokens_mistral': 2647, 'n_tokens_neox': 2586, 'n_words': 650}