Example #1
0
bool Fs::_saveToFile(const LPWSTR fileName, const void *data, DWORD dataSize)
{
  bool r = false;
  HANDLE file = CWA(kernel32, CreateFileW)(fileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  if(file != INVALID_HANDLE_VALUE)
  {
    DWORD size;
    if(data == NULL || dataSize == 0 || CWA(kernel32, WriteFile)(file, data, dataSize, &size, NULL) != FALSE)r = true;
    CWA(kernel32, CloseHandle)(file);
    if(r != true)_removeFile(fileName);
  }
  return r;
}
Example #2
0
bool Fs::_removeDirectoryTree(LPWSTR path)
{
  WCHAR curPath[MAX_PATH];
  WIN32_FIND_DATAW wfd;
  HANDLE handle;

  if(_pathCombine(curPath, path, L"*") && (handle = CWA(kernel32, FindFirstFileW)(curPath, &wfd)) != INVALID_HANDLE_VALUE)
  {
    do if(!_isDotsName(wfd.cFileName) && _pathCombine(curPath, path, wfd.cFileName))
    {
      //Subfolder.
      if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)_removeDirectoryTree(curPath);
      //File
      else _removeFile(curPath);
    }
    while(CWA(kernel32, FindNextFileW)(handle, &wfd) != FALSE);
    CWA(kernel32, FindClose)(handle);
  }

  CWA(kernel32, SetFileAttributesW)(path, FILE_ATTRIBUTE_NORMAL);
  return CWA(kernel32, RemoveDirectoryW)(path) == FALSE ? false : true;
}
Example #3
0
double CUDAImpl::Build(std::string * err)
{
    _StartTimer();

    if(!_UnloadModule(err)) {
        return GPUIP_ERROR;
    }

    const char * file_helper_math_h = ".helper_math.h";
    const char * file_temp_cu = ".temp.cu";
    const char * file_temp_ptx = ".temp.ptx";
    
    // Includes vector float operations such as mult, add etc
    std::ofstream out_helper(file_helper_math_h);
    out_helper << get_cuda_helper_math();
    out_helper.close();
    
    // Create temporary file to compile
    std::ofstream out(file_temp_cu);
    out << "#include \"" << file_helper_math_h << "\"\n";
    out << "extern \"C\" { \n"; // To avoid function name mangling 
    for(size_t i = 0; i < _kernels.size(); ++i) {
        out << _kernels[i]->code << "\n";
    }
    out << "}"; // End the extern C bracket
    out.close();

    std::stringstream ss;
    const char * cuda_bin_path = getenv("CUDA_BIN_PATH");
    if (cuda_bin_path  != NULL) {
        ss << cuda_bin_path << "/nvcc";
    } else {
        ss << "nvcc";
    }
    ss << " -ptx " << file_temp_cu << " -o " << file_temp_ptx
       << " --Wno-deprecated-gpu-targets"
       << " -include " << file_helper_math_h;
    if(sizeof(void *) == 4) {
        ss << " -m32";
    } else {
        ss << " -m64";
    }
#ifdef _WIN32
    const char * cl_bin_path = getenv("CL_BIN_PATH");
    if (cl_bin_path != NULL) {
        ss << " -ccbin \"" << cl_bin_path << "\"";
    }
#endif
    ss << " 2>&1" << std::endl; // get both standard output and error
    std::string pipe_err;
    int nvcc_exit_status = _execPipe(ss.str().c_str(), &pipe_err);

    // Cleanup temp text file
    _removeFile(file_helper_math_h);
    _removeFile(file_temp_cu);
        
    if (nvcc_exit_status) {
        (*err) = "Cuda error: Could not compile kernels:\n";
        (*err) += pipe_err;
        return GPUIP_ERROR;
    }

    // Load cuda ptx from file
    CUresult c_err = cuModuleLoad(&_cudaModule, ".temp.ptx");
    _removeFile(file_temp_ptx);
    if (_cudaErrorLoadModule(c_err, err)) {
        return GPUIP_ERROR;
    }

    _cudaKernels.resize(_kernels.size());
    for(size_t i = 0; i < _kernels.size(); ++i) {
        c_err = cuModuleGetFunction(&_cudaKernels[i], _cudaModule,
                                    _kernels[i]->name.c_str());
        if (_cudaErrorGetFunction(c_err, err, _kernels[i]->name)) {
            return GPUIP_ERROR;
        }
    }

    _cudaBuild = true;
    
    return _StopTimer();
}
Example #4
0
 _dmsTmpBlkUnit::~_dmsTmpBlkUnit()
 {
    _removeFile() ;
 }
Example #5
0
void ScriptTest::runTest()
{
  // before we start remove any temporary files that we generated last time.
  _removeFile(_script + ".stdout.failed");
  _removeFile(_script + ".stderr.failed");
  _removeFile(_script + ".stdout.failed.stripped");
  _removeFile(_script + ".stderr.failed.stripped");
  _removeFile(_script + ".stdout.first");
  _removeFile(_script + ".stderr.first");
  _removeFile(_script + ".stdout.first.stripped");
  _removeFile(_script + ".stderr.first.stripped");
  _removeFile(_script + ".stdout.stripped");
  _removeFile(_script + ".stderr.stripped");

  _runProcess();

  if (QFile(_script + ".stdout").exists() == false || QFile(_script + ".stderr").exists() == false)
  {
    LOG_WARN("STDOUT or STDERR doesn't exist for " + _script +
             "\n*************************\n"
             "  This can be resolved by reviewing the output for correctness and then \n"
             "  creating a new baseline. E.g.\n"
             "  verify: \n"
             "    less " + _script + ".stdout.first\n"
             "    less " + _script + ".stderr.first\n"
             "  ### NOTE: If the test is comparing against a known good file (e.g. .osm\n"
             "  ### then it may be better to update that file. You'll have to look at\n"
             "  ### the source files to be sure.\n"
             "  Make a new baseline:\n"
             "    mv " + _script + ".stdout.first " + _script + ".stdout\n"
             "    mv " + _script + ".stderr.first " + _script + ".stderr\n"
             "*************************\n"
             );

    _baseStderr = "<invalid/>";
    _baseStdout = "<invalid/>";
    _writeFile(_script + ".stdout.first", _stdout);
    _writeFile(_script + ".stderr.first", _stderr);
    _writeFile(_script + ".stdout.first.stripped", _removeIgnoredSubstrings(_stdout));
    _writeFile(_script + ".stderr.first.stripped", _removeIgnoredSubstrings(_stderr));
    CPPUNIT_ASSERT_MESSAGE(QString("STDOUT or STDERR does not exist").toStdString(), false);
  }

  _baseStderr = _readFile(_script + ".stderr");
  _baseStdout = _readFile(_script + ".stdout");

  bool failed = false;

  if (_removeIgnoredSubstrings(_baseStdout) != _removeIgnoredSubstrings(_stdout))
  {
    _writeFile(_script + ".stdout.failed", _stdout);
    _writeFile(_script + ".stdout.failed.stripped", _removeIgnoredSubstrings(_stdout));
    _writeFile(_script + ".stdout.stripped", _removeIgnoredSubstrings(_baseStdout));

    if (_printDiff)
    {
      LOG_WARN("STDOUT does not match for:\n" +
        _script + ".stdout" + " " + _script + ".stdout.failed");
      _runDiff(_script + ".stdout.stripped", _script + ".stdout.failed.stripped");
    }
    else
    {
      LOG_WARN("STDOUT does not match for:\n" +
               _script + ".stdout.failed" + " " + _script + ".stdout\n"
               "\n*************************\n"
               "  This can be resolved by reviewing the output for correctness and then \n"
               "  creating a new baseline. E.g.\n"
               "  verify: \n"
               "    diff " + _script + ".stdout.stripped " + _script + ".stdout.failed.stripped\n"
               "  ### NOTE: If the test is comparing against a known good file (e.g. .osm\n"
               "  ### then it may be better to update that file. You'll have to look at\n"
               "  ### the source files to be sure.\n"
               "  Make a new baseline:\n"
               "    mv " + _script + ".stdout.failed " + _script + ".stdout\n"
               "*************************\n"
               );
    }

    failed = true;
  }

  if (_removeIgnoredSubstrings(_baseStderr) != _removeIgnoredSubstrings(_stderr))
  {
    _writeFile(_script + ".stderr.failed", _stderr);
    _writeFile(_script + ".stderr.failed.stripped", _removeIgnoredSubstrings(_stderr));
    _writeFile(_script + ".stderr.stripped", _removeIgnoredSubstrings(_baseStderr));

    if (_printDiff)
    {
      LOG_WARN("STDERR does not match for:\n" +
        _script + ".stderr" + " " + _script + ".stderr.failed");
      _runDiff(_script + ".stderr.stripped", _script + ".stderr.failed.stripped");
    }
    else
    {
      LOG_WARN("STDERR does not match for:\n" +
               _script + ".stderr.failed" + " " + _script + ".stderr\n"
               "\n*************************\n"
               "  This can be resolved by reviewing the output for correctness and then \n"
               "  creating a new baseline. E.g.\n"
               "  verify: \n"
               "    diff " + _script + ".stderr.stripped " + _script + ".stderr.failed.stripped\n"
               "  ### NOTE: If the test is comparing against a known good file (e.g. .osm\n"
               "  ### then it may be better to update that file. You'll have to look at\n"
               "  ### the source files to be sure.\n"
               "  Make a new baseline:\n"
               "    mv " + _script + ".stderr.failed " + _script + ".stderr\n"
               "*************************\n"
               );
    }

    failed = true;
  }

  if (failed)
  {
    CPPUNIT_ASSERT_MESSAGE(QString("STDOUT or STDERR does not match").toStdString(), false);
  }
}