Esempio n. 1
0
T& CLI::GetParam(const std::string& identifier)
{
  // Only use the alias if the parameter does not exist as given.
  std::string key =
      (GetSingleton().parameters.count(identifier) == 0 &&
       identifier.length() == 1 && GetSingleton().aliases.count(identifier[0]))
      ? GetSingleton().aliases[identifier[0]] : identifier;

  if (GetSingleton().parameters.count(key) == 0)
    Log::Fatal << "Parameter --" << key << " does not exist in this program!"
        << std::endl;

  util::ParamData& d = GetSingleton().parameters[key];

  // Make sure the types are correct.
  if (TYPENAME(T) != d.tname)
    Log::Fatal << "Attempted to access parameter --" << key << " as type "
        << TYPENAME(T) << ", but its true type is " << d.tname << "!"
        << std::endl;

  // We already know that required options have been passed, so we have a valid
  // value to return.  Because the parameters held are sometimes different types
  // than what the user wants, we must pass through a utility function.
  typename util::ParameterType<T>::type& v =
      *boost::any_cast<typename util::ParameterType<T>::type>(&d.value);
  return util::HandleParameter<T>(v, d);
}
Esempio n. 2
0
void CLI::Add(const std::string& path,
              const std::string& description,
              const std::string& alias,
              bool required)
{

  po::options_description& desc = CLI::GetSingleton().desc;
  // Must make use of boost syntax here.
  std::string progOptId = alias.length() ? path + "," + alias : path;

  // Add the alias, if necessary
  AddAlias(alias, path);

  // Add the option to boost program_options.
  desc.add_options()(progOptId.c_str(), po::value<T>(), description.c_str());

  // Make sure the appropriate metadata is inserted into gmap.
  gmap_t& gmap = GetSingleton().globalValues;

  ParamData data;
  T tmp = T();

  data.desc = description;
  data.name = path;
  data.tname = TYPENAME(T);
  data.value = boost::any(tmp);
  data.wasPassed = false;

  gmap[path] = data;

  // If the option is required, add it to the required options list.
  if (required)
    GetSingleton().requiredOptions.push_front(path);
}
Esempio n. 3
0
static int64_t common_seek(SDL_RWops *rw, int64_t offset, int whence) {
	if(!offset && whence == RW_SEEK_CUR) {
		return ZDATA(rw)->pos;
	}

	return SDL_SetError("Can't seek in %s stream", TYPENAME(rw));
}
void memcpytest2_sizes(size_t maxElem=0, size_t offset=0)
{
    printSep();
    printf ("test: %s<%s>\n", __func__,  TYPENAME(T));

    int deviceId;
    HIPCHECK(hipGetDevice(&deviceId));

    size_t free, total;
    HIPCHECK(hipMemGetInfo(&free, &total));

    if (maxElem == 0) {
        maxElem = free/sizeof(T)/5;
    }

    printf ("  device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB)    maxSize=%6.1fMB offset=%lu\n", 
            deviceId, free, (float)(free/1024.0/1024.0), total, (float)(total/1024.0/1024.0), maxElem*sizeof(T)/1024.0/1024.0, offset);

    for (size_t elem=64; elem+offset<=maxElem; elem*=2) {
        HIPCHECK ( hipDeviceReset() );
        memcpytest2<T>(elem+offset, 0, 1, 1, 0);  // unpinned host
        HIPCHECK ( hipDeviceReset() );
        memcpytest2<T>(elem+offset, 1, 1, 1, 0);  // pinned host
    }
}
Esempio n. 5
0
typename util::ParameterType<T>::type& CLI::GetUnmappedParam(
    const std::string& identifier)
{
  std::string key =
      (identifier.length() == 1 && GetSingleton().aliases.count(identifier[0]))
      ? GetSingleton().aliases[identifier[0]] : identifier;

  if (GetSingleton().parameters.count(key) == 0)
    Log::Fatal << "Parameter --" << key << " does not exist in this program!"
        << std::endl;

  util::ParamData& d = GetSingleton().parameters[key];

  // Make sure the types are correct.
  if (TYPENAME(T) != d.tname)
    Log::Fatal << "Attempted to access parameter --" << key << " as type "
        << TYPENAME(T) << ", but its true type is " << d.tname << "!"
        << std::endl;

  return *boost::any_cast<typename util::ParameterType<T>::type>(&d.value);
}
Esempio n. 6
0
  /**
   * Construct an Option object.  When constructed, it will register
   * itself with CLI.
   *
   * @param defaultValue Default value this parameter will be initialized to
   *      (for flags, this should be false, for instance).
   * @param identifier The name of the option (no dashes in front; for --help,
   *      we would pass "help").
   * @param description A short string describing the option.
   * @param alias Short name of the parameter. "" for no alias.
   * @param cppName Name of the C++ type of this parameter (i.e. "int").
   * @param required Whether or not the option is required at runtime.
   * @param input Whether or not the option is an input option.
   * @param noTranspose If the parameter is a matrix and this is true, then the
   *      matrix will not be transposed on loading.
   * @param testName Name of the test (used for identifiying which binding test 
   *      this option belongs to)
   */
  TestOption(const N defaultValue,
             const std::string& identifier,
             const std::string& description,
             const std::string& alias,
             const std::string& cppName,
             const bool required = false,
             const bool input = true,
             const bool noTranspose = false,
             const std::string& testName = "")
  {
    // Create the ParamData object to give to CLI.
    util::ParamData data;

    data.desc = description;
    data.name = identifier;
    data.tname = TYPENAME(N);
    data.alias = alias[0];
    data.wasPassed = false;
    data.noTranspose = noTranspose;
    data.required = required;
    data.input = input;
    data.loaded = false;
    data.cppType = cppName;
    data.value = boost::any(defaultValue);
    data.persistent = false;

    const std::string tname = data.tname;

    CLI::RestoreSettings(testName, false);

    // Set some function pointers that we need.
    CLI::GetSingleton().functionMap[tname]["GetPrintableParam"] =
        &GetPrintableParam<N>;
    CLI::GetSingleton().functionMap[tname]["GetParam"] = &GetParam<N>;
    CLI::GetSingleton().functionMap[tname]["GetAllocatedMemory"] =
        &GetAllocatedMemory<N>;
    CLI::GetSingleton().functionMap[tname]["DeleteAllocatedMemory"] =
        &DeleteAllocatedMemory<N>;

    CLI::Add(std::move(data));

    // If this is an output option, set it as passed.
    if (!input)
      CLI::SetPassed(identifier);

    CLI::StoreSettings(testName);
    CLI::ClearSettings();
  }
void multiThread_1(bool serialize, bool usePinnedHost)
{
    printSep();
    printf ("test: %s<%s> serialize=%d usePinnedHost=%d\n", __func__,  TYPENAME(T), serialize, usePinnedHost);
    std::thread t1 (memcpytest2<T>,N, usePinnedHost,0,0,0);
    if (serialize) {
        t1.join();
    }

    
    std::thread t2 (memcpytest2<T>,N, usePinnedHost,0,0,0);
    if (serialize) {
        t2.join();
    }

    if (!serialize) {
        t1.join();
        t2.join();
    }
}
Esempio n. 8
0
int    font_free_unused(DviDevice *dev)
{
    DviFont    *font, *next;
    int    count = 0;

    DEBUG((DBG_FONTS, "destroying unused fonts\n"));    
    for(font = (DviFont *)fontlist.head; font; font = next) {
        DviFontRef *ref;
        
        next = font->next;
        if(font->links)
            continue;
        count++;
        DEBUG((DBG_FONTS, "removing unused %s font `%s'\n", 
            TYPENAME(font), font->fontname));
        listh_remove(&fontlist, LIST(font));
        if(font->in)
            fclose(font->in);
        /* get rid of subfonts (but can't use `drop_chain' here) */
        for(; (ref = font->subfonts); ) {
            font->subfonts = ref->next;
            mdvi_free(ref);
        }
        /* remove this font */
        font_reset_font_glyphs(dev, font, MDVI_FONTSEL_GLYPH);
        /* let the font destroy its private data */
        if(font->finfo->freedata)
            font->finfo->freedata(font);
        /* destroy characters */
        if(font->chars)
            mdvi_free(font->chars);
        mdvi_free(font->fontname);
        mdvi_free(font->filename);
        mdvi_free(font);
    }
    DEBUG((DBG_FONTS, "%d unused fonts removed\n", count));
    return count;
}
Esempio n. 9
0
void memcpy2Dtest(size_t numW, size_t numH, bool usePinnedHost)
{

  size_t width = numW * sizeof(T);
  size_t sizeElements = width * numH;

  printf("memcpy2Dtest: %s<%s> size=%lu (%6.2fMB) W: %d, H:%d, usePinnedHost: %d\n",
         __func__,
         TYPENAME(T),
         sizeElements, sizeElements/1024.0/1024.0,
         (int)numW, (int)numH, usePinnedHost);

  T *A_d, *B_d, *C_d;
  T *A_h, *B_h, *C_h;

  size_t pitch_A, pitch_B, pitch_C;

  hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
  HipTest::initArrays2DPitch(&A_d, &B_d, &C_d, &pitch_A, &pitch_B, &pitch_C, numW, numH);
  HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW*numH, usePinnedHost);
  unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW*numH);

  HIPCHECK (hipMemcpy2D (A_d, pitch_A, A_h, width, width, numH, hipMemcpyHostToDevice) );
  HIPCHECK (hipMemcpy2D (B_d, pitch_B, B_h, width, width, numH, hipMemcpyHostToDevice) );

  hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d, C_d, (pitch_C/sizeof(T))*numH);

  HIPCHECK (hipMemcpy2D (C_h, width, C_d, pitch_C, width, numH, hipMemcpyDeviceToHost) );

  HIPCHECK ( hipDeviceSynchronize() );
  HipTest::checkVectorADD(A_h, B_h, C_h, numW*numH);

  HipTest::freeArrays (A_d, B_d, C_d, A_h, B_h, C_h, usePinnedHost);

  printf ("  %s success\n", __func__);
}
Esempio n. 10
0
  /**
   * Construct an Option object.  When constructed, it will register
   * itself with CLI.
   *
   * @param defaultValue Default value this parameter will be initialized to
   *      (for flags, this should be false, for instance).
   * @param identifier The name of the option (no dashes in front; for --help,
   *      we would pass "help").
   * @param description A short string describing the option.
   * @param alias Short name of the parameter. "" for no alias.
   * @param cppName Name of the C++ type of this parameter (i.e. "int").
   * @param required Whether or not the option is required at runtime.
   * @param input Whether or not the option is an input option.
   * @param noTranspose If the parameter is a matrix and this is true, then the
   *      matrix will not be transposed on loading.
   * @param testName Is not used and added for compatibility reasons.
   */
  CLIOption(const N defaultValue,
            const std::string& identifier,
            const std::string& description,
            const std::string& alias,
            const std::string& cppName,
            const bool required = false,
            const bool input = true,
            const bool noTranspose = false,
            const std::string& /*testName*/ = "")
  {
    // Create the ParamData object to give to CLI.
    util::ParamData data;

    data.desc = description;
    data.name = identifier;
    data.tname = TYPENAME(N);
    data.alias = alias[0];
    data.wasPassed = false;
    data.noTranspose = noTranspose;
    data.required = required;
    data.input = input;
    data.loaded = false;
    data.persistent = false; // All CLI parameters are not persistent.
    data.cppType = cppName;

    // Apply default value.
    if (std::is_same<typename std::remove_pointer<N>::type,
                     typename ParameterType<typename
                         std::remove_pointer<N>::type>::type>::value)
    {
      data.value = boost::any(defaultValue);
    }
    else
    {
      typename ParameterType<typename std::remove_pointer<N>::type>::type tmp;
      data.value = boost::any(std::tuple<N, decltype(tmp)>(defaultValue, tmp));
    }

    const std::string tname = data.tname;
    const std::string boostName = MapParameterName<
        typename std::remove_pointer<N>::type>(identifier);
    std::string progOptId = (alias[0] != '\0') ? boostName + ","
        + std::string(1, alias[0]) : boostName;

    // Do a check to ensure that the boost name isn't already in use.
    const std::map<std::string, util::ParamData>& parameters =
        CLI::Parameters();
    if (parameters.count(boostName) > 0)
    {
      // Create a fake Log::Fatal since it may not yet be initialized.
      // Temporarily define color code escape sequences.
      #ifndef _WIN32
        #define BASH_RED "\033[0;31m"
        #define BASH_CLEAR "\033[0m"
      #else
        #define BASH_RED ""
        #define BASH_CLEAR ""
      #endif

      // Temporary outstream object for detecting duplicate identifiers.
      util::PrefixedOutStream outstr(std::cerr,
            BASH_RED "[FATAL] " BASH_CLEAR, false, true /* fatal */);

      #undef BASH_RED
      #undef BASH_CLEAR

      outstr << "Parameter --" << boostName << " (" << data.alias << ") "
             << "is defined multiple times with the same identifiers."
             << std::endl;
    }

    CLI::Add(std::move(data));

    // Set some function pointers that we need.
    CLI::GetSingleton().functionMap[tname]["DefaultParam"] =
        &DefaultParam<N>;
    CLI::GetSingleton().functionMap[tname]["OutputParam"] =
        &OutputParam<N>;
    CLI::GetSingleton().functionMap[tname]["GetPrintableParam"] =
        &GetPrintableParam<N>;
    CLI::GetSingleton().functionMap[tname]["StringTypeParam"] =
        &StringTypeParam<N>;
    CLI::GetSingleton().functionMap[tname]["GetParam"] = &GetParam<N>;
    CLI::GetSingleton().functionMap[tname]["GetRawParam"] = &GetRawParam<N>;
    CLI::GetSingleton().functionMap[tname]["AddToPO"] = &AddToPO<N>;
    CLI::GetSingleton().functionMap[tname]["MapParameterName"] =
        &MapParameterName<N>;
    CLI::GetSingleton().functionMap[tname]["SetParam"] = &SetParam<N>;
    CLI::GetSingleton().functionMap[tname]["GetPrintableParamName"] =
        &GetPrintableParamName<N>;
    CLI::GetSingleton().functionMap[tname]["GetPrintableParamValue"] =
        &GetPrintableParamValue<N>;
    CLI::GetSingleton().functionMap[tname]["GetAllocatedMemory"] =
        &GetAllocatedMemory<N>;
    CLI::GetSingleton().functionMap[tname]["DeleteAllocatedMemory"] =
        &DeleteAllocatedMemory<N>;
  }
Esempio n. 11
0
	bool CAddition::Do(Energy* E)
	{
		ePipeline* Pipe = (ePipeline*)E;
		
		if (Pipe->Size()<2)
		{
			return false;
		}
		eElectron    DataA;
		eElectron    DataB;
		
		Pipe->Pop(&DataA);
		Pipe->Pop(&DataB);
		
		uint32 TypeA = DataA.EnergyType();
		uint32 TypeB = DataB.EnergyType();
	
		if(TypeA == TYPE_INT)
		{
			int64 a = DataA.Int64();
			if (TypeB == TYPE_INT)
			{
				int64 b = DataB.Int64(); 
				
				Pipe->PushInt(a+b);
				return true;
			}else if (TypeB == TYPE_FLOAT)
			{
				float64 f = DataB.Float64();
                
				int64 b = (int64)f;
				
				Pipe->PushInt(a+b);
				return true;
			}
		}else if (TypeA == TYPE_FLOAT)
		{
			float64 a = DataA.Float64();
			if (TypeB == TYPE_INT)
			{
				int64 t = DataB.Int64();		
                float64 b = (float64)t;

				Pipe->PushFloat(a+b);
				return true;
				
			}else if (TypeB == TYPE_FLOAT)
			{
				float64 b = DataB.Float64();
				
				Pipe->PushFloat(a+b);
				return true;
			}
		}

		Pipe->GetLabel()=Format1024(_T("%I64ld Error: %s and %s can't make addition(+) operator!"),m_ID,TYPENAME(TypeA),TYPENAME(TypeB));
		return false;
	}
Esempio n. 12
0
void CLI::Add(const std::string& identifier,
              const std::string& description,
              const std::string& alias,
              const bool required,
              const bool input)
{
  // Temporarily define color code escape sequences.
  #ifndef _WIN32
    #define BASH_RED "\033[0;31m"
    #define BASH_CLEAR "\033[0m"
  #else
    #define BASH_RED ""
    #define BASH_CLEAR ""
  #endif

  // Temporary outstream object for detecting duplicate identifiers.
  util::PrefixedOutStream outstr(std::cerr,
        BASH_RED "[FATAL] " BASH_CLEAR, false, true /* fatal */);

  #undef BASH_RED
  #undef BASH_CLEAR

  // Define identifier and alias maps.
  gmap_t& gmap = GetSingleton().globalValues;
  amap_t& amap = GetSingleton().aliasValues;

  // If found in current map, print fatal error and terminate the program.
  if (gmap.count(identifier))
    outstr << "Parameter --" << identifier << "(-" << alias << ") "
           << "is defined multiple times with same identifiers." << std::endl;
  if (amap.count(alias))
    outstr << "Parameter --" << identifier << "(-" << alias << ") "
           << "is defined multiple times with same alias." << std::endl;

  po::options_description& desc = CLI::GetSingleton().desc;
  // Must make use of boost syntax here.
  std::string progOptId =
          alias.length() ? identifier + "," + alias : identifier;

  // Add the alias, if necessary
  AddAlias(alias, identifier);

  // Add the option to boost program_options.
  desc.add_options()(progOptId.c_str(), po::value<T>(), description.c_str());

  // Make sure the appropriate metadata is inserted into gmap.
  ParamData data;
  T tmp = T();

  data.desc = description;
  data.name = identifier;
  data.tname = TYPENAME(T);
  data.value = boost::any(tmp);
  data.wasPassed = false;

  gmap[identifier] = data;

  // If the option is required, add it to the required options list.
  if (required)
    GetSingleton().requiredOptions.push_front(identifier);

  // Depending on whether or not the option is input or output, add it to the
  // appropriate list.
  if (input)
    GetSingleton().inputOptions.push_front(identifier);
  else
    GetSingleton().outputOptions.push_front(identifier);
}
Esempio n. 13
0
void CLI::Add(const T& defaultValue,
              const std::string& identifier,
              const std::string& description,
              const char alias,
              const bool required,
              const bool input,
              const bool noTranspose)
{
  // Temporarily define color code escape sequences.
  #ifndef _WIN32
    #define BASH_RED "\033[0;31m"
    #define BASH_CLEAR "\033[0m"
  #else
    #define BASH_RED ""
    #define BASH_CLEAR ""
  #endif

  // Temporary outstream object for detecting duplicate identifiers.
  util::PrefixedOutStream outstr(std::cerr,
        BASH_RED "[FATAL] " BASH_CLEAR, false, true /* fatal */);

  #undef BASH_RED
  #undef BASH_CLEAR

  // Define identifier and alias maps.
  std::map<std::string, util::ParamData>& parameters =
      GetSingleton().parameters;
  std::map<char, std::string>& aliases = GetSingleton().aliases;

  // If found in current map, print fatal error and terminate the program.
  if (parameters.count(identifier))
    outstr << "Parameter --" << identifier << " (-" << alias << ") "
           << "is defined multiple times with the same identifiers."
           << std::endl;
  if (alias != '\0' && aliases.count(alias))
    outstr << "Parameter --" << identifier << " (-" << alias << ") "
           << "is defined multiple times with the same alias." << std::endl;

  // Add the parameter to the map of parameters.  We must hold two boost::any
  // types, in case the type that boost::po receives will be different than the
  // type we want (like for matrices).
  util::ParamData data;
  typename util::ParameterType<T>::type tmp;
  T mappedTmp;

  data.desc = description;
  data.name = identifier;
  data.tname = TYPENAME(T);
  data.alias = alias;
  data.isFlag = (TYPENAME(T) == TYPENAME(bool));
  data.noTranspose = noTranspose;
  data.required = required;
  data.input = input;
  data.loaded = false;
  data.boostName = util::MapParameterName<T>(identifier);

  // Apply default value.
  if (std::is_same<T, typename util::ParameterType<T>::type>::value)
  {
    data.value = boost::any(defaultValue);
    data.mappedValue = boost::any(mappedTmp);
  }
  else
  {
    data.value = boost::any(tmp);
    data.mappedValue = boost::any(defaultValue);
  }

  // Sanity check: ensure that the boost name is not already in use.
  std::map<std::string, util::ParamData>::const_iterator it =
      parameters.begin();
  while (it != parameters.end())
  {
    if ((*it).second.boostName == data.boostName ||
        (*it).second.name == data.boostName)
      outstr << "Parameter --" << data.boostName << " (" << alias << ") "
             << "is defined multiple times with the same identifiers."
             << std::endl;
    ++it;
  }

  GetSingleton().parameters[identifier] = data;

  // Now add the parameter name to boost::program_options.
  po::options_description& desc = CLI::GetSingleton().desc;
  // Must make use of boost syntax here.
  std::string progOptId = (alias != '\0') ? data.boostName + ","
      + std::string(1, alias) : data.boostName;

  // Add the alias, if necessary.
  if (alias != '\0')
    GetSingleton().aliases[alias] = identifier;

  // Add the option to boost program_options.
  if (data.isFlag)
    desc.add_options()(progOptId.c_str(), description.c_str());
  else
    GetSingleton().AddOption<typename util::ParameterType<T>::type>(progOptId.c_str(),
        description.c_str());

  // If the option is required, add it to the required options list.
  if (required)
    GetSingleton().requiredOptions.push_front(identifier);

  // Depending on whether or not the option is input or output, add it to the
  // appropriate list.
  if (!input)
    GetSingleton().outputOptions.push_front(identifier);
}
Esempio n. 14
0
bool TokenSource::peekToken() {
  bool result = true;
  if(!d_inreserve) {
    char c;
    d_so.peekCharacter(c," \n");
    if(c=='+') {
      d_type = PLUS;
      d_s = "+";
      d_n = -999;
    } else if(c=='/') {
      d_type = DIVIDE;
      d_s = "/";
      d_n = -999;
    } else if(c=='_') {
      d_type = PATTERN;
      d_s = "_";
      d_n = -999;
    } else if(c=='*') {
      d_so.passCharacter();
      d_so.peekCharacter(c," \n");
      if(c!='*') {
        GBStream << "Stars must appear in pairs.\n";
        DBG();
      };
      d_so.passCharacter();
      d_type = DOUBLESTAR;
      d_s = "**";
      d_n = -999;
    } else if('0'<=c && c<='9') {
      d_type = INTEGER;
      d_s = "invalid";
      int n = d_so.grabInteger();
    } else if(c='\"') {
      int dummy;
      d_type = STRING;
      d_s = getString(dummy);
      d_n = -999;
    } else if(c=='[') {
      d_type = LBRACKET;
      d_s = "[";
      d_n = -999;
    } else if(c==']') {
      d_type = RBRACKET;
      d_s = "]";
      d_n = -999;
    } else if(c=='{') {
      d_type = LCURLY;
      d_s = "[";
      d_n = -999;
    } else if(c=='}') {
      d_type = RCURLY;
      d_s = "]";
      d_n = -999;
    } else if(c==',') {
      d_type = COMMA;
      d_s = ",";
      d_n = -999;
    } else if(('a'<=c&&c<='z') ||('A'<=c&&c<='Z'))  {
      int dummy;
      d_type = SYMBOL;
      d_s = getAlphaNumWord(dummy);
      d_n = -999;
    } else {
      GBStream << "Encounted unexpected character " << c << '\n';
      GBStream << "The last token encounted has string " << d_s 
               << " and integer " << n 
               << " and was of type " << TYPENAME(d_type) << '\n';
      DBG();
    };
  };
};
Esempio n. 15
0
  /**
   * Construct a PyOption object.  When constructed, it will register itself
   * with CLI. The testName parameter is not used and added for compatibility 
   * reasons.
   */
  PyOption(const T defaultValue,
           const std::string& identifier,
           const std::string& description,
           const std::string& alias,
           const std::string& cppName,
           const bool required = false,
           const bool input = true,
           const bool noTranspose = false,
           const std::string& /*testName*/ = "")
  {
    // Create the ParamData object to give to CLI.
    util::ParamData data;

    data.desc = description;
    data.name = identifier;
    data.tname = TYPENAME(T);
    data.alias = alias[0];
    data.wasPassed = false;
    data.noTranspose = noTranspose;
    data.required = required;
    data.input = input;
    data.loaded = false;
    // Only "verbose" and "copy_all_inputs" will be persistent.
    if (identifier == "verbose" || identifier == "copy_all_inputs")
      data.persistent = true;
    else
      data.persistent = false;
    data.cppType = cppName;

    // Every parameter we'll get from Python will have the correct type.
    data.value = boost::any(defaultValue);

    // Restore the parameters for this program.
    if (identifier != "verbose" && identifier != "copy_all_inputs")
      CLI::RestoreSettings(programName, false);

    // Set the function pointers that we'll need.  All of these function
    // pointers will be used by both the program that generates the pyx, and
    // also the binding itself.  (The binding itself will only use GetParam,
    // GetPrintableParam, and GetRawParam.)
    CLI::GetSingleton().functionMap[data.tname]["GetParam"] = &GetParam<T>;
    CLI::GetSingleton().functionMap[data.tname]["GetPrintableParam"] =
        &GetPrintableParam<T>;

    // These are used by the pyx generator.
    CLI::GetSingleton().functionMap[data.tname]["PrintClassDefn"] =
        &PrintClassDefn<T>;
    CLI::GetSingleton().functionMap[data.tname]["PrintDefn"] = &PrintDefn<T>;
    CLI::GetSingleton().functionMap[data.tname]["PrintDoc"] = &PrintDoc<T>;
    CLI::GetSingleton().functionMap[data.tname]["PrintOutputProcessing"] =
        &PrintOutputProcessing<T>;
    CLI::GetSingleton().functionMap[data.tname]["PrintInputProcessing"] =
        &PrintInputProcessing<T>;
    CLI::GetSingleton().functionMap[data.tname]["ImportDecl"] = &ImportDecl<T>;

    // Add the ParamData object, then store.  This is necessary because we may
    // import more than one .so that uses CLI, so we have to keep the options
    // separate.  programName is a global variable from mlpack_main.hpp.
    CLI::Add(std::move(data));
    if (identifier != "verbose" && identifier != "copy_all_inputs")
      CLI::StoreSettings(programName);
    CLI::ClearSettings();
  }
Esempio n. 16
0
static int load_one_glyph(DviContext *dvi, DviFont *font, int code)
{
    BITMAP *map;
    DviFontChar *ch;
    int    status;

#ifndef NODEBUG
    ch = FONTCHAR(font, code);
    DEBUG((DBG_GLYPHS, "loading glyph code %d in %s (at %u)\n",
        code, font->fontname, ch->offset));
#endif
    if(font->finfo->getglyph == NULL) {
        /* font type does not need to load glyphs (e.g. vf) */
        return 0;
    }

    status = font->finfo->getglyph(&dvi->params, font, code);
    if(status < 0)
        return -1;
    /* get the glyph again (font->chars may have changed) */
    ch = FONTCHAR(font, code);
#ifndef NODEBUG
    map = (BITMAP *)ch->glyph.data;
    if(DEBUGGING(BITMAP_DATA)) {
        DEBUG((DBG_BITMAP_DATA,
            "%s: new %s bitmap for character %d:\n",
            font->fontname, TYPENAME(font), code));
        if(MDVI_GLYPH_ISEMPTY(map))
            DEBUG((DBG_BITMAP_DATA, "blank bitmap\n"));
        else
            bitmap_print(stderr, map);
    }
#endif
    /* check if we have to scale it */
    if(!font->finfo->scalable && font->hdpi != font->vdpi) {
        int    hs, vs, d;
        
        /* we scale it ourselves */
        d = Max(font->hdpi, font->vdpi);
        hs = d / font->hdpi;
        vs = d / font->vdpi;
        if(ch->width && ch->height && (hs > 1 || vs > 1)) {
            int    h, v;
            DviGlyph glyph;
            
            DEBUG((DBG_FONTS, 
                "%s: scaling glyph %d to resolution %dx%d\n",
                font->fontname, code, font->hdpi, font->vdpi));
            h = dvi->params.hshrink;
            v = dvi->params.vshrink;
            d = dvi->params.density;
            dvi->params.hshrink = hs;
            dvi->params.vshrink = vs;
            dvi->params.density = 50;
            /* shrink it */
            font->finfo->shrink0(dvi, font, ch, &glyph);
            /* restore parameters */
            dvi->params.hshrink = h;
            dvi->params.vshrink = v;
            dvi->params.density = d;
            /* update glyph data */
            if(!MDVI_GLYPH_ISEMPTY(ch->glyph.data))
                bitmap_destroy((BITMAP *)ch->glyph.data);
            ch->glyph.data = glyph.data;
            ch->glyph.x = glyph.x;
            ch->glyph.y = glyph.y;
            ch->glyph.w = glyph.w;
            ch->glyph.h = glyph.h;
        }
            
    }
    font_transform_glyph(dvi->params.orientation, &ch->glyph);
        
    return 0;
}
Esempio n. 17
0
static int64_t common_size(SDL_RWops *rw) {
	return SDL_SetError("Can't get size of %s stream", TYPENAME(rw));
}
void memcpytest2(size_t numElements, bool usePinnedHost, bool useHostToHost, bool useDeviceToDevice, bool useMemkindDefault)
{
    size_t sizeElements = numElements * sizeof(T);
    printf ("test: %s<%s> size=%lu (%6.2fMB) usePinnedHost:%d, useHostToHost:%d, useDeviceToDevice:%d, useMemkindDefault:%d\n", 
            __func__, 
            TYPENAME(T),
            sizeElements, sizeElements/1024.0/1024.0,
            usePinnedHost, useHostToHost, useDeviceToDevice, useMemkindDefault);


    T *A_d, *B_d, *C_d;
    T *A_h, *B_h, *C_h;


    HipTest::initArrays (&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, numElements, usePinnedHost);
    unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);

    T *A_hh = NULL;
    T *B_hh = NULL;
    T *C_dd = NULL;



    if (useHostToHost) {
        if (usePinnedHost) {
            HIPCHECK ( hipHostMalloc((void**)&A_hh, sizeElements, hipHostMallocDefault) );
            HIPCHECK ( hipHostMalloc((void**)&B_hh, sizeElements, hipHostMallocDefault) );
        } else {
            A_hh = (T*)malloc(sizeElements);
            B_hh = (T*)malloc(sizeElements);
        }


        // Do some extra host-to-host copies here to mix things up:
        HIPCHECK ( hipMemcpy(A_hh, A_h, sizeElements, useMemkindDefault? hipMemcpyDefault : hipMemcpyHostToHost));
        HIPCHECK ( hipMemcpy(B_hh, B_h, sizeElements, useMemkindDefault? hipMemcpyDefault : hipMemcpyHostToHost));


        HIPCHECK ( hipMemcpy(A_d, A_hh, sizeElements, useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
        HIPCHECK ( hipMemcpy(B_d, B_hh, sizeElements, useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
    } else {
        HIPCHECK ( hipMemcpy(A_d, A_h, sizeElements, useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
        HIPCHECK ( hipMemcpy(B_d, B_h, sizeElements, useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
    }

    hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d, C_d, numElements);

    if (useDeviceToDevice) {
        HIPCHECK ( hipMalloc(&C_dd, sizeElements) );

        // Do an extra device-to-device copies here to mix things up:
        HIPCHECK ( hipMemcpy(C_dd, C_d,  sizeElements, useMemkindDefault? hipMemcpyDefault : hipMemcpyDeviceToDevice));

        //Destroy the original C_d:
        HIPCHECK ( hipMemset(C_d, 0x5A, sizeElements));

        HIPCHECK ( hipMemcpy(C_h, C_dd, sizeElements, useMemkindDefault? hipMemcpyDefault:hipMemcpyDeviceToHost));
    } else {
        HIPCHECK ( hipMemcpy(C_h, C_d, sizeElements, useMemkindDefault? hipMemcpyDefault:hipMemcpyDeviceToHost));
    }

    HIPCHECK ( hipDeviceSynchronize() );
    HipTest::checkVectorADD(A_h, B_h, C_h, numElements);

    HipTest::freeArrays (A_d, B_d, C_d, A_h, B_h, C_h, usePinnedHost);

    printf ("  %s success\n", __func__);
}
Esempio n. 19
0
void memcpyArraytest(size_t numW, size_t numH, bool usePinnedHost, bool usePitch=false)
{

  size_t width = numW * sizeof(T);
  size_t sizeElements = width * numH;

  printf("memcpyArraytest: %s<%s> size=%lu (%6.2fMB) W: %d, H: %d, usePinnedHost: %d, usePitch: %d\n",
         __func__,
         TYPENAME(T),
         sizeElements, sizeElements/1024.0/1024.0,
         (int)numW, (int)numH, usePinnedHost, usePitch);

  hipArray *A_d, *B_d, *C_d;
  T *A_h, *B_h, *C_h;

  // 1D
  if ((numW >= 1) && (numH == 1)) {
    hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
    HipTest::initHIPArrays(&A_d, &B_d, &C_d, &desc, numW, 1, 0);
    HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW*numH, usePinnedHost);
    unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW*numH);

    HIPCHECK (hipMemcpyToArray (A_d, 0, 0, (void *)A_h, width, hipMemcpyHostToDevice) );
    HIPCHECK (hipMemcpyToArray (B_d, 0, 0, (void *)B_h, width, hipMemcpyHostToDevice) );

    hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, (T*)A_d->data, (T*)B_d->data, (T*)C_d->data, numW);

    HIPCHECK (hipMemcpy (C_h, C_d->data, width, hipMemcpyDeviceToHost) );

    HIPCHECK ( hipDeviceSynchronize() );
    HipTest::checkVectorADD(A_h, B_h, C_h, numW);

  }
  // 2D
  else if ((numW >= 1) && (numH >= 1)) {


    hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
    HipTest::initHIPArrays(&A_d, &B_d, &C_d, &desc, numW, numH, 0);
    HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW*numH, usePinnedHost);
    unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW*numH);

    if (usePitch) {
      T *A_p, *B_p, *C_p;
      size_t pitch_A, pitch_B, pitch_C;

      HipTest::initArrays2DPitch(&A_p, &B_p, &C_p, &pitch_A, &pitch_B, &pitch_C, numW, numH);
      HIPCHECK (hipMemcpy2D (A_p, pitch_A, A_h, width, width, numH, hipMemcpyHostToDevice) );
      HIPCHECK (hipMemcpy2D (B_p, pitch_B, B_h, width, width, numH, hipMemcpyHostToDevice) );

      HIPCHECK (hipMemcpy2DToArray (A_d, 0, 0, (void *)A_p, pitch_A, width, numH, hipMemcpyDeviceToDevice) );
      HIPCHECK (hipMemcpy2DToArray (B_d, 0, 0, (void *)B_p, pitch_B, width, numH, hipMemcpyDeviceToDevice) );

      hipFree(A_p);
      hipFree(B_p);
      hipFree(C_p);
    }
    else {
      HIPCHECK (hipMemcpy2DToArray (A_d, 0, 0, (void *)A_h, width, width, numH, hipMemcpyHostToDevice) );
      HIPCHECK (hipMemcpy2DToArray (B_d, 0, 0, (void *)B_h, width, width, numH, hipMemcpyHostToDevice) );
    }

    hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, (T*)A_d->data, (T*)B_d->data, (T*)C_d->data, numW*numH);

    HIPCHECK (hipMemcpy2D ((void*)C_h, width, (void*)C_d->data, width, width, numH, hipMemcpyDeviceToHost) );

    HIPCHECK ( hipDeviceSynchronize() );
    HipTest::checkVectorADD(A_h, B_h, C_h, numW*numH);
  }
  // Unknown
  else {
    HIPASSERT("Incompatible dimensions" && 0);
  }

  hipFreeArray(A_d);
  hipFreeArray(B_d);
  hipFreeArray(C_d);
  HipTest::freeArraysForHost(A_h, B_h, C_h, usePinnedHost);

  printf ("  %s success\n", __func__);

}