Commit 341fa160 authored by Trung Nguyen's avatar Trung Nguyen
Browse files

Updated UCL_Device built with OpenCL to use platforms that support accelerators by default

parent 6c42c9b3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -609,7 +609,7 @@ $(OBJ_DIR)/lal_lj_expand_coul_long.o: $(ALL_H) lal_lj_expand_coul_long.h lal_lj_
$(OBJ_DIR)/lal_lj_expand_coul_long_ext.o: $(ALL_H) lal_lj_expand_coul_long.h lal_lj_expand_coul_long_ext.cpp lal_base_charge.h
	$(OCL) -o $@ -c lal_lj_expand_coul_long_ext.cpp -I$(OBJ_DIR)

$(BIN_DIR)/ocl_get_devices: ./geryon/ucl_get_devices.cpp
$(BIN_DIR)/ocl_get_devices: ./geryon/ucl_get_devices.cpp $(OCL_H)
	$(OCL) -o $@ ./geryon/ucl_get_devices.cpp -DUCL_OPENCL $(OCL_LINK) 

$(OCL_LIB): $(OBJS) $(PTXS)
+101 −67
Original line number Diff line number Diff line
@@ -280,6 +280,9 @@ class UCL_Device {
  /// Return the OpenCL type for the device
  inline cl_device_id & cl_device() { return _cl_device; }

  /// Select the platform that has accelerators
  inline void set_platform_accelerator(int pid=-1);

 private:
  int _num_platforms;          // Number of platforms
  int _platform;               // UCL_Device ID for current platform
@@ -311,8 +314,8 @@ UCL_Device::UCL_Device() {
    return;
  } else
    _num_platforms=static_cast<int>(nplatforms);

  set_platform(0);
  // note that platform 0 may not necessarily be associated with accelerators
  set_platform_accelerator();
}

UCL_Device::~UCL_Device() {
@@ -320,6 +323,7 @@ UCL_Device::~UCL_Device() {
}

void UCL_Device::clear() {
  _properties.clear();
  if (_device>-1) {
    for (size_t i=0; i<_cq.size(); i++) {
      CL_DESTRUCT_CALL(clReleaseCommandQueue(_cq.back()));
@@ -529,8 +533,15 @@ int UCL_Device::set(int num) {
  return create_context();
}

// List all devices along with all properties
// List all devices from all platforms along with all properties
void UCL_Device::print_all(std::ostream &out) {
  // --- loop through the platforms
  for (int n=0; n<_num_platforms; n++) {

    set_platform(n);

    out << "\nPlatform " << n << ":\n";

    if (num_devices() == 0)
      out << "There is no device supporting OpenCL\n";
    for (int i=0; i<num_devices(); ++i) {
@@ -597,7 +608,30 @@ void UCL_Device::print_all(std::ostream &out) {
          << max_sub_devices(i) << std::endl;
    }
  }
}

// Select the platform that is associated with accelerators
// if pid < 0, select the first platform
void UCL_Device::set_platform_accelerator(int pid) {
  if (pid < 0) {
    int found = 0;
    for (int n=0; n<_num_platforms; n++) {
      set_platform(n);
      for (int i=0; i<num_devices(); i++) {
        if (_properties[i].device_type==CL_DEVICE_TYPE_CPU ||
            _properties[i].device_type==CL_DEVICE_TYPE_GPU ||
            _properties[i].device_type==CL_DEVICE_TYPE_ACCELERATOR) {
          found = 1;
          break;
        }
      }
      if (found) break;
    }
  } else {
    set_platform(pid);
  }
}

} // namespace ucl_opencl 

#endif