Example #1
0
  void 
  RTSpheres::sortTick(const magnet::GL::Camera& camera)
  {
    cl_float4 campos = getclVec(camera.getEyeLocation());
    cl_float4 camdir = getclVec(camera.getCameraDirection());
    cl_float4 camup = getclVec(camera.getCameraUp());
  
    //Generate the sort data
    _sortDataKernelFunc(_spherePositions, _sortKeys, _sortData,
			campos, camdir, camup,
			(cl_float)camera.getAspectRatio(),
			(cl_float)camera.getZNear(),
			(cl_float)camera.getFOVY(),
			_N);
  
    if ((_renderDetailLevels.size() > 2) 
	|| (_renderDetailLevels.front()._nSpheres != _N))
      sortFunctor(_sortKeys, _sortData);
  
    recolor();
  }
// cbEVT_COMPLETE_CODE
void CCManager::OnCompleteCode(CodeBlocksEvent& event)
{
    event.Skip();

    cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
    if (!ed)
        return;
    cbCodeCompletionPlugin* ccPlugin = GetProviderFor(ed);
    if (!ccPlugin)
        return;

    cbStyledTextCtrl* stc = ed->GetControl();
    int tknEnd = stc->GetCurrentPos();
    if (tknEnd == m_LastACLaunchState[lsCaretStart] && !m_AutocompTokens.empty())
    {
        DoBufferedCC(stc);
        return;
    }
    int tknStart = stc->WordStartPosition(tknEnd, true);

    m_AutocompTokens = ccPlugin->GetAutocompList(event.GetInt() == FROM_TIMER,
                                                 ed, tknStart, tknEnd);
    if (m_AutocompTokens.empty())
        return;

    bool isPureAlphabetical = true;
    TokenSorter sortFunctor(isPureAlphabetical);
    std::sort(m_AutocompTokens.begin(), m_AutocompTokens.end(), sortFunctor);
    if (isPureAlphabetical)
        stc->AutoCompSetOrder(wxSCI_ORDER_PRESORTED);
    else
        stc->AutoCompSetOrder(wxSCI_ORDER_CUSTOM);
    wxString items;
    // experimentally, the average length per token seems to be 23 for the main CC plugin
    items.Alloc(m_AutocompTokens.size() * 20); // TODO: measure performance
    for (size_t i = 0; i < m_AutocompTokens.size(); ++i)
    {
        items += m_AutocompTokens[i].displayName;
        if (m_AutocompTokens[i].category == -1)
            items += wxT("\r");
        else
            items += F(wxT("\n%d\r"), m_AutocompTokens[i].category);
    }
    items.RemoveLast();

    if (!stc->CallTipActive() && !stc->AutoCompActive())
        m_CallTipActive = wxSCI_INVALID_POSITION;

    stc->AutoCompSetIgnoreCase(true);
    stc->AutoCompSetMaxHeight(14);
    stc->AutoCompSetTypeSeparator(wxT('\n'));
    stc->AutoCompSetSeparator(wxT('\r'));
    stc->AutoCompShow(tknEnd - tknStart, items);
    m_OwnsAutocomp = true;
    if (isPureAlphabetical)
    {
        const wxString& contextStr = stc->GetTextRange(tknStart, stc->WordEndPosition(tknEnd, true));
        std::vector<cbCodeCompletionPlugin::CCToken>::const_iterator tknIt
                = std::lower_bound(m_AutocompTokens.begin(), m_AutocompTokens.end(),
                                   cbCodeCompletionPlugin::CCToken(-1, contextStr),
                                   sortFunctor);
        if (tknIt != m_AutocompTokens.end() && tknIt->displayName.StartsWith(contextStr))
            stc->AutoCompSelect(tknIt->displayName);
    }
    m_LastACLaunchState[lsTknStart] = tknStart;
    m_LastACLaunchState[lsCaretStart] = tknEnd;
}
Example #3
0
bool runTestType(cl::Context context, cl::CommandQueue queue)
{
  cl_uint size = 64 * 256;

  std::vector<T> input(size);

  for(size_t i = 0; i < input.size(); ++i)
    input[i] = input.size() - i - 1;
  
  // create input buffer using pinned memory
  cl::Buffer bufferIn(context, CL_MEM_ALLOC_HOST_PTR |
		      CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE, 
		      sizeof(T) * input.size(), &input[0])
    ;
  
  magnet::CL::sort<T> sortFunctor;
  sortFunctor.build(queue, context);
  sortFunctor(bufferIn);

  std::cout << "##Testing generic sort (";
  switch(sortFunctor.getMode())
    {
    case magnet::CL::sort<T>::CPU:
      std::cout << "HeapSort";
      break;
    case magnet::CL::sort<T>::NVIDIA:
      std::cout << "radixNVIDIA";
      break;
    case magnet::CL::sort<T>::AMD:
      std::cout << "radixAMD";
      break;
    default:
      M_throw() << "Could not determine which sorting algorithm is being used";
    }

  std::cout << ") for " << input.size() << " elements and type " 
	    << magnet::CL::detail::traits<T>::kernel_type();
  

  std::vector<T> output(size);
 
  queue.enqueueReadBuffer(bufferIn, CL_TRUE, 0, input.size() *
			  sizeof(T), &output[0]);

  bool failed = !testOutput(input, output);

  std::cout << " key(only) " << (failed ? "FAILED" : "PASSED") << ", "; 

  //Now test with some data!
  //Refresh the input array
  queue.enqueueWriteBuffer(bufferIn, CL_TRUE, 0, input.size() *
			   sizeof(T), &input[0]);

  //Write a data array
  std::vector<cl_uint> data(size);
  for(size_t i = 0; i < input.size(); ++i)
    data[i] = i;

  cl::Buffer dataIn(context, CL_MEM_ALLOC_HOST_PTR |
		    CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE, 
		    sizeof(cl_uint) * data.size(), &data[0])
    ;

  sortFunctor(bufferIn, dataIn);
  
  queue.enqueueReadBuffer(dataIn, CL_TRUE, 0, data.size() *
			  sizeof(cl_uint), &data[0]);

  bool keyfail = false;//!testOutput(input, output);

  std::cout << " key " << (keyfail ? "FAILED" : "PASSED"); 

  bool datafail = false;
  for(size_t i = 0; i < input.size(); ++i)
    if (data[i] != input.size() - 1 - i)
      datafail = true;

  std::cout << " data " << (datafail ? "FAILED" : "PASSED") << std::endl;
  
  return failed || keyfail || datafail;
}