Package com.diablominer.DiabloMiner

Examples of com.diablominer.DiabloMiner.DiabloMinerFatalException


      logBuffer.get(log);

      System.out.println(new String(log));

      throw new DiabloMinerFatalException(diabloMiner, "Failed to build program on " + deviceName);
    }

    if(hasBFI_INT) {
      diabloMiner.info("BFI_INT patching enabled, disabling hardware check errors");
      hwcheck = false;

      int binarySize = (int) program.getInfoSizeArray(CL10.CL_PROGRAM_BINARY_SIZES)[0];

      ByteBuffer binary = BufferUtils.createByteBuffer(binarySize);
      program.getInfoBinaries(binary);

      for(int pos = 0; pos < binarySize - 4; pos++) {
        if((long) (0xFFFFFFFF & binary.getInt(pos)) == 0x464C457FL && (long) (0xFFFFFFFF & binary.getInt(pos + 4)) == 0x64010101L) {
          boolean firstText = true;

          int offset = binary.getInt(pos + 32);
          short entrySize = binary.getShort(pos + 46);
          short entryCount = binary.getShort(pos + 48);
          short index = binary.getShort(pos + 50);

          int header = pos + offset;

          int nameTableOffset = binary.getInt(header + index * entrySize + 16);
          int size = binary.getInt(header + index * entrySize + 20);

          int entry = header;

          for(int section = 0; section < entryCount; section++) {
            int nameIndex = binary.getInt(entry);
            offset = binary.getInt(entry + 16);
            size = binary.getInt(entry + 20);

            int name = pos + nameTableOffset + nameIndex;

            if((long) (0xFFFFFFFF & binary.getInt(name)) == 0x7865742E) {
              if(firstText) {
                firstText = false;
              } else {
                int sectionStart = pos + offset;
                for(int i = 0; i < size / 8; i++) {
                  long instruction1 = (long) (0xFFFFFFFF & binary.getInt(sectionStart + i * 8));
                  long instruction2 = (long) (0xFFFFFFFF & binary.getInt(sectionStart + i * 8 + 4));

                  if((instruction1 & 0x02001000L) == 0x00000000L && (instruction2 & 0x9003F000L) == 0x0001A000L) {
                    instruction2 ^= (0x0001A000L ^ 0x0000C000L);

                    binary.putInt(sectionStart + i * 8 + 4, (int) instruction2);
                  }
                }
              }
            }

            entry += entrySize;
          }

          break;
        }
      }

      IntBuffer binaryErr = BufferUtils.createIntBuffer(1);

      CL10.clReleaseProgram(program);
      program = CL10.clCreateProgramWithBinary(context, device, binary, binaryErr, null);

      err = CL10.clBuildProgram(program, device, compileOptions, null);

      if(err != CL10.CL_SUCCESS) {
        throw new DiabloMinerFatalException(diabloMiner, "Failed to BFI_INT patch kernel on " + deviceName);
      }
    }

    kernel = CL10.clCreateKernel(program, "search", null);
    if(kernel == null) {
      throw new DiabloMinerFatalException(diabloMiner, "Failed to create kernel on " + deviceName);

    }

    if(forceWorkSize == 0) {
      ByteBuffer rkwgs = BufferUtils.createByteBuffer(8);
View Full Code Here


      try {
        digestInside = MessageDigest.getInstance("SHA-256");
        digestOutside = MessageDigest.getInstance("SHA-256");
      } catch(NoSuchAlgorithmException e) {
        throw new DiabloMinerFatalException(diabloMiner, "Your Java implementation does not have a MessageDigest for SHA-256");
      }

      queue = CL10.clCreateCommandQueue(context, device, 0, errBuffer);

      if(queue == null || errBuffer.get(0) != CL10.CL_SUCCESS) {
        throw new DiabloMinerFatalException(diabloMiner, "Failed to allocate queue");
      }

      IntBuffer blankinit = BufferUtils.createIntBuffer(OUTPUTS * 4);

      for(int i = 0; i < OUTPUTS; i++)
        blankinit.put(0);

      blankinit.rewind();

      if(platform_version == PlatformVersion.V1_1)
        blank = CL10.clCreateBuffer(context, CL10.CL_MEM_COPY_HOST_PTR | CL10.CL_MEM_READ_ONLY, blankinit, errBuffer);
      else
        blank = CL10.clCreateBuffer(context, CL10.CL_MEM_COPY_HOST_PTR | CL10.CL_MEM_READ_ONLY | CL12.CL_MEM_HOST_NO_ACCESS, blankinit, errBuffer);

      if(blank == null || errBuffer.get(0) != CL10.CL_SUCCESS)
        throw new DiabloMinerFatalException(diabloMiner, "Failed to allocate blank buffer");

      blankinit.rewind();

      for(int i = 0; i < 2; i++) {
        if(platform_version == PlatformVersion.V1_1)
          output[i] = CL10.clCreateBuffer(context, CL10.CL_MEM_COPY_HOST_PTR | CL10.CL_MEM_WRITE_ONLY, blankinit, errBuffer);
        else
          output[i] = CL10.clCreateBuffer(context, CL10.CL_MEM_COPY_HOST_PTR | CL10.CL_MEM_WRITE_ONLY | CL12.CL_MEM_HOST_READ_ONLY, blankinit, errBuffer);

        blankinit.rewind();

        if(output[i] == null || errBuffer.get(0) != CL10.CL_SUCCESS) {
          throw new DiabloMinerFatalException(diabloMiner, "Failed to allocate output buffer");
        }
      }

      outputBuffer = CL10.clEnqueueMapBuffer(queue, output[outputIndex], 1, CL10.CL_MAP_READ, 0, OUTPUTS * 4, null, null, null);

View Full Code Here

          err = CL10.clEnqueueNDRangeKernel(queue, kernel, 1, workBaseBuffer, workSizeBuffer, localWorkSize, null, null);

          if(err != CL10.CL_SUCCESS && err != CL10.CL_INVALID_KERNEL_ARGS && err != CL10.CL_INVALID_GLOBAL_OFFSET) {
            try {
              throw new DiabloMinerFatalException(diabloMiner, "Failed to queue kernel, error " + err);
            } catch(DiabloMinerFatalException e) {
            }
          } else {
            if(err == CL10.CL_INVALID_KERNEL_ARGS) {
              diabloMiner.debug("Spurious CL_INVALID_KERNEL_ARGS error, ignoring");
View Full Code Here

        else
          pos += ret;
      }

      if(pos == 0)
        throw new DiabloMinerFatalException(diabloMiner, "Unable to read DiabloMiner.cl");

      source = new String(data).trim();
      stream.close();
    } catch(IOException e) {
      throw new DiabloMinerFatalException(diabloMiner, "Unable to read DiabloMiner.cl");
    }

    String sourceLines[] = source.split("\n");
    source = "";

    long vectorBase = 0;

    Integer[] vectors = diabloMiner.getGPUVectors();
    totalVectors = 0;
    int totalVectorsPOT;

    for(Integer vector : vectors) {
      totalVectors += vector;
    }

    if(totalVectors > 16)
      throw new DiabloMinerFatalException(diabloMiner, "DiabloMiner does not support more than 16 total vectors yet");

    int powtwo = 1 << (32 - Integer.numberOfLeadingZeros(totalVectors) - 1);

    if(totalVectors != powtwo)
      totalVectorsPOT = 1 << (32 - Integer.numberOfLeadingZeros(totalVectors));
    else
      totalVectorsPOT = totalVectors;

    for(int x = 0; x < sourceLines.length; x++) {
      String sourceLine = sourceLines[x];

      if(diabloMiner.getGPUNoArray() && !sourceLine.contains("z ZA")) {
        sourceLine = sourceLine.replaceAll("ZA\\[([0-9]+)\\]", "ZA$1");
      }

      if(sourceLine.contains("zz")) {
        if(totalVectors > 1)
          sourceLine = sourceLine.replaceAll("zz", String.valueOf(totalVectorsPOT));
        else
          sourceLine = sourceLine.replaceAll("zz", "");
      }

      if(sourceLine.contains("= (io) ? Znonce")) {
        int count = 0;
        String change = "(uintzz)(";

        for(int z = 0; z < vectors.length; z++) {
          change += UPPER[z] + "nonce";
          count += vectors[z];

          if(z != vectors.length - 1)
            change += ", ";
        }

        for(int z = count; z < totalVectorsPOT; z++)
          change += ", 0";

        change += ")";

        sourceLine = sourceLine.replace("Znonce", change);

        if(totalVectors > 1)
          sourceLine = sourceLine.replaceAll("zz", String.valueOf(totalVectorsPOT));
        else
          sourceLine = sourceLine.replaceAll("zz", "");

        source += sourceLine + "\n";
      } else if((sourceLine.contains("Z") || sourceLine.contains("z")) && !sourceLine.contains("__")) {
        for(int y = 0; y < vectors.length; y++) {
          String replace = sourceLine;

          if(diabloMiner.getGPUNoArray() && replace.contains("z ZA")) {
            replace = "";

            for(int z = 0; z < 930; z += 5) {
              replace += "     ";

              for(int w = 0; w < 5; w++)
                replace += "z ZA" + (z + w) + "; ";

              replace += "\n";
            }
          }

          if(vectors[y] > 1 && replace.contains("typedef")) {
            replace = replace.replace("uint", "uint" + vectors[y]);
          } else if(replace.contains("z Znonce")) {
            String vectorGlobal;

            if(vectors[y] > 1)
              vectorGlobal = " + (uint" + vectors[y] + ")(";
            else
              vectorGlobal = " + (uint)(";

            for(int i = 0; i < vectors[y]; i++) {
              vectorGlobal += Long.toString((vectorBase + i));

              if(i != vectors[y] - 1)
                vectorGlobal += ", ";
            }

            vectorGlobal += ");";

            replace = replace.replace(";", vectorGlobal);

            vectorBase += vectors[y];
          }

          if(vectors[y] == 1 && replace.contains("bool Zio")) {
            replace = replace.replace("any(", "(");
          }

          source += replace.replaceAll("Z", UPPER[y]).replaceAll("z", LOWER[y]) + "\n";
        }
      } else if(totalVectors == 1 && sourceLine.contains("any(nonce")) {
        source += sourceLine.replace("any", "") + "\n";
      } else if(sourceLine.contains("__global")) {
        if(totalVectors > 1)
          source += sourceLine.replaceAll("uint", "uint" + totalVectorsPOT) + "\n";
        else
          source += sourceLine + "\n";
      } else {
        source += sourceLine + "\n";
      }
    }

    if(diabloMiner.getGPUDebugSource()) {
      System.out.println("\n---\n" + source);
      throw new DiabloMinerFatalException(diabloMiner, "Debug kernel source output, quitting");
    }


    targetFPSBasis = 1000.0 / (diabloMiner.getGPUTargetFPS());

    List<CLPlatform> platforms = null;

    try {
      CL.create();

      platforms = CLPlatform.getPlatforms();
    } catch(Exception e) {
      throw new DiabloMinerFatalException(diabloMiner, "Failed to initialize OpenCL, make sure your environment is setup correctly");
    }

    if(platforms == null || platforms.isEmpty())
      throw new DiabloMinerFatalException(diabloMiner, "No OpenCL platforms found");

    Set<String> enabledDevices = diabloMiner.getEnabledDevices();
    int count = 1;
    int platformCount = 0;

    for(CLPlatform platform : platforms) {
      PlatformVersion version;

      diabloMiner.info("Using " + platform.getInfoString(CL10.CL_PLATFORM_NAME).trim() + " " + platform.getInfoString(CL10.CL_PLATFORM_VERSION));

      String versions = platform.getInfoString(CL10.CL_PLATFORM_VERSION);
      if(versions.contains("OpenCL 1.0"))
        version = PlatformVersion.V1_0;
      else if (versions.contains("OpenCL 1.1"))
        version = PlatformVersion.V1_1;
      else
        version = PlatformVersion.V1_2;

      if(version == PlatformVersion.V1_0) {
        diabloMiner.error("OpenCL platform " + platform.getInfoString(CL10.CL_PLATFORM_NAME).trim() + " is not OpenCL 1.1 or later");
        continue;
      }

      List<CLDevice> devices = platform.getDevices(CL10.CL_DEVICE_TYPE_GPU | CL10.CL_DEVICE_TYPE_ACCELERATOR);

      if(devices == null || devices.isEmpty()) {
        diabloMiner.error("OpenCL platform " + platform.getInfoString(CL10.CL_PLATFORM_NAME).trim() + " contains no devices");
        continue;
      }

      if(devices != null) {
        for(CLDevice device : devices) {
          if(enabledDevices == null || enabledDevices.contains(platformCount + "." + count) || enabledDevices.contains(Integer.toString(count))) {
            String deviceName = device.getInfoString(CL10.CL_DEVICE_NAME).trim() + " (#" + count + ")";
            deviceStates.add(new GPUDeviceState(this, deviceName, platform, version, device));
          }

          count++;
        }
      }

      platformCount++;
    }

    if(deviceStates.size() == 0)
      throw new DiabloMinerFatalException(diabloMiner, "No OpenCL devices found");
  }
View Full Code Here

TOP

Related Classes of com.diablominer.DiabloMiner.DiabloMinerFatalException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.