Beispiel #1
0
cl_int
clBuildProgram(cl_program           program,
               cl_uint              num_devices,
               const cl_device_id * device_list,
               const char *         options,
               void (*pfn_notify)(cl_program program, void * user_data),
               void *               user_data)
{
#ifdef DBG_API
  std::cerr << "Entering clBuildProgram. Building for " << num_devices
    << " devices\n";
#endif
  
    if (!program->isA(Coal::Object::T_Program)) {
      std::cerr << "INVALID_PROGRAM\n";
        return CL_INVALID_PROGRAM;
    }

    if (!device_list && num_devices > 0) {
      std::cerr << "!device_list : INVALID_VALUE\n";
        return CL_INVALID_VALUE;
    }

    if (!num_devices && device_list) {
      std::cerr << "!num_devices : INVALID_VALUE\n";
        return CL_INVALID_VALUE;
    }

    if (!pfn_notify && user_data) {
      std::cerr << "!pfn_notify : INVALID_VALUE\n";
        return CL_INVALID_VALUE;
    }
    // We cannot try to build a previously-failed program
    if (program->state() != Coal::Program::Loaded)
      return CL_INVALID_OPERATION;

#ifdef DBG_API
    std::cerr << "Checking " << num_devices << " devices\n";
#endif
    // Check the devices for compliance
    //if (num_devices)
    //{
        cl_uint context_num_devices = 0;
        cl_device_id *context_devices;
        Coal::Context *context = (Coal::Context *)program->parent();
        cl_int result;

        result = context->info(CL_CONTEXT_NUM_DEVICES, sizeof(cl_uint),
                                     &context_num_devices, 0);

        if (result != CL_SUCCESS)
            return result;

        context_devices =
            (cl_device_id *)std::malloc(context_num_devices * sizeof(cl_device_id));

        result = context->info(CL_CONTEXT_DEVICES,
                                     context_num_devices * sizeof(cl_device_id),
                                     context_devices, 0);

        if (result != CL_SUCCESS) {
#ifdef DBG_API
          std::cerr << "context->info != CL_SUCCESS\n";
#endif
            return result;
        }

#ifdef DBG_API
        std::cerr << "Checking " << context_num_devices << " context devices\n";
#endif

        if (num_devices) {
          for (cl_uint i=0; i < num_devices; ++i) {
            bool found = false;
#ifdef DBG_API
            std::cerr << "device_list[" << i << "] addr = "
              << device_list[i] << std::endl;
#endif

            for (cl_uint j=0; j<context_num_devices; ++j)
            {
#ifdef DBG_API
              std::cerr << "context_device [" << j << "] addr = "
                << context_devices[j] << std::endl;
#endif
                if (device_list[i] == context_devices[j])
                {
                    found = true;
#ifdef DBG_API
                    std::cerr << "Found device, break out\n";
#endif
                    break;
                }
            }

            if (!found) {
              std::cerr << "INVALID_DEVICE\n";
              return CL_INVALID_DEVICE;
            }
        }
#ifdef DEBUCL
        std::cerr << "Leaving clBuildProgram after program->build\n";
#endif
        // Build program
        return program->build(options, pfn_notify, user_data, num_devices,
                              (Coal::DeviceInterface * const*)device_list);
      }
      // num devices wasn't specified and device_list is probably null, so
      // build for all associated devices
      else {
#ifdef DEBUCL
        std::cerr << "Leaving clBuildProgram after program->build\n";
#endif
        return program->build(options, pfn_notify, user_data,
                              context_num_devices,
                              context->getAllDevices());
      }
  return NULL;
}
Beispiel #2
0
cl_int
clBuildProgram(cl_program           program,
               cl_uint              num_devices,
               const cl_device_id * device_list,
               const char *         options,
               void (*pfn_notify)(cl_program program, void * user_data),
               void *               user_data)
{
    if (!program->isA(Coal::Object::T_Program))
        return CL_INVALID_PROGRAM;

    if (!device_list && num_devices > 0)
        return CL_INVALID_VALUE;

    if (!num_devices && device_list)
        return CL_INVALID_VALUE;

    if (!pfn_notify && user_data)
        return CL_INVALID_VALUE;

    // Check the devices for compliance
    if (num_devices)
    {
        cl_uint context_num_devices = 0;
        cl_device_id *context_devices;
        Coal::Context *context = (Coal::Context *)program->parent();
        cl_int result;

        result = context->info(CL_CONTEXT_NUM_DEVICES, sizeof(cl_uint),
                                     &context_num_devices, 0);

        if (result != CL_SUCCESS)
            return result;

        context_devices =
            (cl_device_id *)std::malloc(context_num_devices * sizeof(cl_device_id));

        result = context->info(CL_CONTEXT_DEVICES,
                                     context_num_devices * sizeof(cl_device_id),
                                     context_devices, 0);

        if (result != CL_SUCCESS)
            return result;

        for (cl_uint i=0; i<num_devices; ++i)
        {
            bool found = false;

            for (cl_uint j=0; j<context_num_devices; ++j)
            {
                if (device_list[i] == context_devices[j])
                {
                    found = true;
                    break;
                }
            }

            if (!found)
                return CL_INVALID_DEVICE;
        }
    }

    // We cannot try to build a previously-failed program
    if (program->state() != Coal::Program::Loaded)
        return CL_INVALID_OPERATION;

    // Build program
    return program->build(options, pfn_notify, user_data, num_devices,
                          (Coal::DeviceInterface * const*)device_list);
}