Пример #1
0
    def test_OpenCL_CSR(self):
        logger.info("Testing CSR-based algorithm (backward-integration)")
        for devtype in ("GPU", "CPU"):
            ids = ocl.select_device(devtype, best=True)
            if ids is None:
                logger.error("No suitable %s OpenCL device found" % devtype)
                continue
            else:
                logger.info("I found a suitable device %s %s: %s %s " % (devtype, ids, ocl.platforms[ids[0]], ocl.platforms[ids[0]].devices[ids[1]]))

            for ds in self.datasets:
                ai = pyFAI.load(ds["poni"])
                data = fabio.open(ds["img"]).data
                ref = ai.integrate1d(data, self.N, method="splitBBox", unit="2th_deg")
                try:
                    res = ai.integrate1d(data, self.N, method="ocl_csr_%i,%i" % (ids[0], ids[1]), unit="2th_deg")
                except (pyFAI.opencl.pyopencl.MemoryError, MemoryError, pyFAI.opencl.pyopencl.RuntimeError, RuntimeError) as error:
                    logger.warning("Memory error on %s dataset %s: %s%s. Converted into Warning: device may not have enough memory." % (devtype, os.path.basename(ds["img"]), os.linesep, error))
                    break
                else:
                    r = Rwp(ref, res)
                    logger.info("OpenCL CSR vs histogram SplitBBox has R= %.3f for dataset %s" % (r, ds))
                    self.assertTrue(r < 3, "Rwp=%.3f for OpenCL CSR processing of %s" % (r, ds))
                del ai, data
                gc.collect()
Пример #2
0
    def test_OpenCL_LUT(self):
        logger.info("Testing LUT-based algorithm (backward-integration)")
        for devtype in ("GPU", "CPU"):
            ids = ocl.select_device(devtype, best=True)
            if ids is None:
                logger.error("No suitable %s OpenCL device found" % devtype)
                continue
            else:
                logger.info("I found a suitable device %s %s: %s %s " % (devtype, ids, ocl.platforms[ids[0]], ocl.platforms[ids[0]].devices[ids[1]]))

            for ds in self.datasets:
                ai = pyFAI.load(ds["poni"])
                data = fabio.open(ds["img"]).data
                try:
                    res = ai.xrpd_LUT_OCL(data, 1000, devicetype="all", platformid=ids[0], deviceid=ids[1])
                except MemoryError as error:
                    logger.warning("Memory Error on %s dataset %s: %s%s. Converted into warnining: device may not have enough memory." % (devtype, os.path.basename(ds["img"]), os.linesep, error))
                else:
                    t0 = time.time()
                    ref = ai.xrpd(data, 1000)
                    t1 = time.time()
                    res = ai.xrpd_LUT_OCL(data, 1000, safe=False)
                    t2 = time.time()
                    logger.info("For image %15s;\tspeed up is %.3fx;\trate is %.3f Hz" % (os.path.basename(ds["img"]), ((t1 - t0) / (t2 - t1)), 1. / (t2 - t1)))
                    r = Rwp(ref, res)
                    self.assertTrue(r < 10, "Rwp=%.3f for OpenCL processing of %s" % (r, ds))
Пример #3
0
    def test_OpenCL(self):
        logger.info("Testing histogram-based algorithm (forward-integration)")
        for devtype in ("GPU", "CPU"):
            ids = ocl.select_device(devtype,
                                    extensions=["cl_khr_int64_base_atomics"])
            if ids is None:
                logger.error("No suitable %s OpenCL device found" % devtype)
                continue
            else:
                logger.info("I found a suitable device %s %s: %s %s " %
                            (devtype, ids, ocl.platforms[ids[0]],
                             ocl.platforms[ids[0]].devices[ids[1]]))

            for ds in self.datasets:
                ai = pyFAI.load(ds["poni"])
                data = fabio.open(ds["img"]).data
                res = ai.xrpd_OpenCL(data,
                                     self.N,
                                     devicetype="all",
                                     platformid=ids[0],
                                     deviceid=ids[1],
                                     useFp64=True)
                ref = ai.integrate1d(data,
                                     self.N,
                                     method="splitBBox",
                                     unit="2th_deg")
                r = Rwp(ref, res)
                logger.info(
                    "OpenCL histogram vs histogram SplitBBox has R= %.3f for dataset %s"
                    % (r, ds))
                self.assertTrue(
                    r < 6,
                    "Rwp=%.3f for OpenCL histogram processing of %s" % (r, ds))
                del ai, data
                gc.collect()
Пример #4
0
    def test_OpenCL(self):
        logger.info("Testing histogram-based algorithm (forward-integration)")
        for devtype in ("GPU", "CPU"):
            ids = ocl.select_device(devtype,
                                    extensions=["cl_khr_int64_base_atomics"])
            if ids is None:
                logger.error("No suitable %s OpenCL device found" % devtype)
                continue
            else:
                logger.info("I found a suitable device %s %s: %s %s " %
                            (devtype, ids, ocl.platforms[ids[0]],
                             ocl.platforms[ids[0]].devices[ids[1]]))

            for ds in self.datasets:
                ai = pyFAI.load(ds["poni"])
                data = fabio.open(ds["img"]).data
                res = ai.xrpd_OpenCL(data,
                                     1000,
                                     devicetype="all",
                                     platformid=ids[0],
                                     deviceid=ids[1],
                                     useFp64=True)
                t0 = time.time()
                ref = ai.xrpd(data, 1000)
                t1 = time.time()
                res = ai.xrpd_OpenCL(data, 1000, safe=False)
                t2 = time.time()
                logger.info(
                    "For image %15s;\tspeed up is %.3fx;\trate is %.3f Hz" %
                    (os.path.basename(ds["img"]),
                     ((t1 - t0) / (t2 - t1)), 1. / (t2 - t1)))
                r = Rwp(ref, res)
                self.assertTrue(
                    r < 10, "Rwp=%.3f for OpenCL processing of %s" % (r, ds))
Пример #5
0
    def test_correct(self):
        test2d = {"numpy": self.eps,
                  "cython": self.eps,
                  "splitbbox": self.eps,
                  "splitpix": self.eps,
                  "lut": self.eps,
                  }
        if ocl:
            for device in ["cpu", "gpu", "acc"]:
                if ocl.select_device(dtype=device):
                    test2d["lut_ocl_%s" % device] = self.eps
                    test2d["csr_ocl_%s" % device] = self.eps
        test2d_direct = {"xrpd2_numpy": 0.3,  # histograms are very noisy in 2D
                         "xrpd2_histogram": 0.3,  # histograms are very noisy in 2D
                         "xrpd2_splitBBox": self.eps,
                         "xrpd2_splitPixel": self.eps}

        for meth in test2d:
            logger.info("About to test2d %s" % meth)
            try:
                I, _, _ = self.ai.integrate2d(self.raw, self.bins, self.azim, unit="r_mm", method=meth, correctSolidAngle=False, dark=self.dark, flat=self.flat)
            except (MemoryError, pyFAI.opencl.pyopencl.MemoryError):
                logger.warning("Got MemoryError from OpenCL device")
                continue
            I = I[numpy.where(I > 0)]
            logger.info("2D method:%s Imin=%s Imax=%s <I>=%s std=%s" % (meth, I.min(), I.max(), I.mean(), I.std()))
            self.assertAlmostEqual(I.mean(), 1, 2, "Mean should be 1 in %s" % meth)
            self.assert_(I.max() - I.min() < test2d[meth], "deviation should be small with meth %s, got %s" % (meth, I.max() - I.min()))
        for meth in test2d_direct:
            logger.info("About to test2d_direct %s" % meth)
            I, _, _ = self.ai.__getattribute__(meth)(self.raw, self.bins, self.azim, correctSolidAngle=False, dark=self.dark, flat=self.flat)
            I = I[numpy.where(I > 0)]
            logger.info("1D method:%s Imin=%s Imax=%s <I>=%s std=%s" % (meth, I.min(), I.max(), I.mean(), I.std()))
            self.assert_(abs(I.mean() - 1) < test2d_direct[meth], "Mean should be 1 in %s" % meth)
            self.assert_(I.max() - I.min() < test2d_direct[meth], "deviation should be small with meth %s, got %s" % (meth, I.max() - I.min()))
Пример #6
0
    def test_correct(self):
        all_methods = [
            "numpy", "cython", "splitbbox", "splitpix", "lut", "csr"
        ]
        if ocl:
            for device in ["cpu", "gpu", "acc"]:
                if ocl.select_device(dtype=device):
                    all_methods.append("lut_ocl_%s" % device)
                    all_methods.append("csr_ocl_%s" % device)

        for meth in all_methods:
            r, I = self.ai.integrate1d(self.raw,
                                       self.bins,
                                       unit="r_mm",
                                       method=meth,
                                       correctSolidAngle=False,
                                       dark=self.dark,
                                       flat=self.flat)
            logger.info("1D method:%s Imin=%s Imax=%s <I>=%s std=%s" %
                        (meth, I.min(), I.max(), I.mean(), I.std()))
            self.assertAlmostEqual(I.mean(), 1, 2,
                                   "Mean should be 1 in %s" % meth)
            self.assert_(
                I.max() - I.min() < self.eps,
                "deviation should be small with meth %s, got %s" %
                (meth, I.max() - I.min()))
        for meth in [
                "xrpd_numpy", "xrpd_cython", "xrpd_splitBBox",
                "xrpd_splitPixel"
        ]:  # , "xrpd_OpenCL" ]: bug with 32 bit GPU and request 64 bit integration
            r, I = self.ai.__getattribute__(meth)(self.raw,
                                                  self.bins,
                                                  correctSolidAngle=False,
                                                  dark=self.dark,
                                                  flat=self.flat)
            logger.info("1D method:%s Imin=%s Imax=%s <I>=%s std=%s" %
                        (meth, I.min(), I.max(), I.mean(), I.std()))
            self.assertAlmostEqual(I.mean(), 1, 2,
                                   "Mean should be 1 in %s" % meth)
            self.assert_(
                I.max() - I.min() < self.eps,
                "deviation should be small with meth %s, got %s" %
                (meth, I.max() - I.min()))
        if ocl and pyFAI.opencl.ocl.select_device("gpu",
                                                  extensions=["cl_khr_fp64"]):
            meth = "xrpd_OpenCL"
            r, I = self.ai.__getattribute__(meth)(self.raw,
                                                  self.bins,
                                                  correctSolidAngle=False,
                                                  dark=self.dark,
                                                  flat=self.flat)
            logger.info("1D method:%s Imin=%s Imax=%s <I>=%s std=%s" %
                        (meth, I.min(), I.max(), I.mean(), I.std()))
            self.assertAlmostEqual(I.mean(), 1, 2,
                                   "Mean should be 1 in %s" % meth)
            self.assert_(
                I.max() - I.min() < self.eps,
                "deviation should be small with meth %s, got %s" %
                (meth, I.max() - I.min()))
Пример #7
0
    def test_OpenCL_LUT(self):
        logger.info("Testing LUT-based algorithm (backward-integration)")
        for devtype in ("GPU", "CPU"):
            ids = ocl.select_device(devtype, best=True)
            if ids is None:
                logger.error("No suitable %s OpenCL device found" % devtype)
                continue
            else:
                logger.info("I found a suitable device %s %s: %s %s " %
                            (devtype, ids, ocl.platforms[ids[0]],
                             ocl.platforms[ids[0]].devices[ids[1]]))

            for ds in self.datasets:
                ai = pyFAI.load(ds["poni"])
                data = fabio.open(ds["img"]).data
                ref = ai.integrate1d(data,
                                     self.N,
                                     method="splitBBox",
                                     unit="2th_deg")
                try:
                    res = ai.integrate1d(data,
                                         self.N,
                                         method="ocl_lut_%i,%i" %
                                         (ids[0], ids[1]),
                                         unit="2th_deg")
                except (pyFAI.opencl.pyopencl.MemoryError, MemoryError,
                        pyFAI.opencl.pyopencl.RuntimeError,
                        RuntimeError) as error:
                    logger.warning(
                        "Memory error on %s dataset %s: %s%s. Converted into warnining: device may not have enough memory."
                        % (devtype, os.path.basename(
                            ds["img"]), os.linesep, error))
                    break
                else:
                    ref = ai.xrpd(data, self.N)
                    r = Rwp(ref, res)
                    logger.info(
                        "OpenCL CSR vs histogram SplitBBox has R= %.3f for dataset %s"
                        % (r, ds))
                    self.assertTrue(
                        r < 3,
                        "Rwp=%.3f for OpenCL LUT processing of %s" % (r, ds))
                del ai, data
                gc.collect()
Пример #8
0
    def test_correct(self):
        all_methods = ["numpy", "cython", "splitbbox", "splitpix", "lut", "csr"]
        if ocl:
            for device in ["cpu", "gpu", "acc"]:
                if ocl.select_device(dtype=device):
                    all_methods.append("lut_ocl_%s" % device)
                    all_methods.append("csr_ocl_%s" % device)

        for meth in all_methods:
            r, I = self.ai.integrate1d(
                self.raw, self.bins, unit="r_mm", method=meth, correctSolidAngle=False, dark=self.dark, flat=self.flat
            )
            logger.info("1D method:%s Imin=%s Imax=%s <I>=%s std=%s" % (meth, I.min(), I.max(), I.mean(), I.std()))
            self.assertAlmostEqual(I.mean(), 1, 2, "Mean should be 1 in %s" % meth)
            self.assert_(
                I.max() - I.min() < self.eps,
                "deviation should be small with meth %s, got %s" % (meth, I.max() - I.min()),
            )
        for meth in [
            "xrpd_numpy",
            "xrpd_cython",
            "xrpd_splitBBox",
            "xrpd_splitPixel",
        ]:  # , "xrpd_OpenCL" ]: bug with 32 bit GPU and request 64 bit integration
            r, I = self.ai.__getattribute__(meth)(
                self.raw, self.bins, correctSolidAngle=False, dark=self.dark, flat=self.flat
            )
            logger.info("1D method:%s Imin=%s Imax=%s <I>=%s std=%s" % (meth, I.min(), I.max(), I.mean(), I.std()))
            self.assertAlmostEqual(I.mean(), 1, 2, "Mean should be 1 in %s" % meth)
            self.assert_(
                I.max() - I.min() < self.eps,
                "deviation should be small with meth %s, got %s" % (meth, I.max() - I.min()),
            )
        if ocl and pyFAI.opencl.ocl.select_device("gpu", extensions=["cl_khr_fp64"]):
            meth = "xrpd_OpenCL"
            r, I = self.ai.__getattribute__(meth)(
                self.raw, self.bins, correctSolidAngle=False, dark=self.dark, flat=self.flat
            )
            logger.info("1D method:%s Imin=%s Imax=%s <I>=%s std=%s" % (meth, I.min(), I.max(), I.mean(), I.std()))
            self.assertAlmostEqual(I.mean(), 1, 2, "Mean should be 1 in %s" % meth)
            self.assert_(
                I.max() - I.min() < self.eps,
                "deviation should be small with meth %s, got %s" % (meth, I.max() - I.min()),
            )
Пример #9
0
    def test_OpenCL(self):
        logger.info("Testing histogram-based algorithm (forward-integration)")
        for devtype in ("GPU", "CPU"):
            ids = ocl.select_device(devtype, extensions=["cl_khr_int64_base_atomics"])
            if ids is None:
                logger.error("No suitable %s OpenCL device found" % devtype)
                continue
            else:
                logger.info("I found a suitable device %s %s: %s %s " % (devtype, ids, ocl.platforms[ids[0]], ocl.platforms[ids[0]].devices[ids[1]]))

            for ds in self.datasets:
                ai = pyFAI.load(ds["poni"])
                data = fabio.open(ds["img"]).data
                res = ai.xrpd_OpenCL(data, self.N, devicetype="all", platformid=ids[0], deviceid=ids[1], useFp64=True)
                ref = ai.integrate1d(data, self.N, method="splitBBox", unit="2th_deg")
                r = Rwp(ref, res)
                logger.info("OpenCL histogram vs histogram SplitBBox has R= %.3f for dataset %s" % (r, ds))
                self.assertTrue(r < 6, "Rwp=%.3f for OpenCL histogram processing of %s" % (r, ds))
                del ai, data
                gc.collect()
Пример #10
0
    def test_OpenCL_LUT(self):
        logger.info("Testing LUT-based algorithm (backward-integration)")
        for devtype in ("GPU", "CPU"):
            ids = ocl.select_device(devtype, best=True)
            if ids is None:
                logger.error("No suitable %s OpenCL device found" % devtype)
                continue
            else:
                logger.info("I found a suitable device %s %s: %s %s " %
                            (devtype, ids, ocl.platforms[ids[0]],
                             ocl.platforms[ids[0]].devices[ids[1]]))

            for ds in self.datasets:
                ai = pyFAI.load(ds["poni"])
                data = fabio.open(ds["img"]).data
                try:
                    res = ai.xrpd_LUT_OCL(data,
                                          1000,
                                          devicetype="all",
                                          platformid=ids[0],
                                          deviceid=ids[1])
                except MemoryError as error:
                    logger.warning(
                        "Memory Error on %s dataset %s: %s%s. Converted into warnining: device may not have enough memory."
                        % (devtype, os.path.basename(
                            ds["img"]), os.linesep, error))
                else:
                    t0 = time.time()
                    ref = ai.xrpd(data, 1000)
                    t1 = time.time()
                    res = ai.xrpd_LUT_OCL(data, 1000, safe=False)
                    t2 = time.time()
                    logger.info(
                        "For image %15s;\tspeed up is %.3fx;\trate is %.3f Hz"
                        % (os.path.basename(ds["img"]),
                           ((t1 - t0) / (t2 - t1)), 1. / (t2 - t1)))
                    r = Rwp(ref, res)
                    self.assertTrue(
                        r < 10,
                        "Rwp=%.3f for OpenCL processing of %s" % (r, ds))
Пример #11
0
    def test_OpenCL(self):
        logger.info("Testing histogram-based algorithm (forward-integration)")
        for devtype in ("GPU", "CPU"):
            ids = ocl.select_device(devtype, extensions=["cl_khr_int64_base_atomics"])
            if ids is None:
                logger.error("No suitable %s OpenCL device found" % devtype)
                continue
            else:
                logger.info("I found a suitable device %s %s: %s %s " % (devtype, ids, ocl.platforms[ids[0]], ocl.platforms[ids[0]].devices[ids[1]]))

            for ds in self.datasets:
                ai = pyFAI.load(ds["poni"])
                data = fabio.open(ds["img"]).data
                res = ai.xrpd_OpenCL(data, 1000, devicetype="all", platformid=ids[0], deviceid=ids[1], useFp64=True)
                t0 = time.time()
                ref = ai.xrpd(data, 1000)
                t1 = time.time()
                res = ai.xrpd_OpenCL(data, 1000, safe=False)
                t2 = time.time()
                logger.info("For image %15s;\tspeed up is %.3fx;\trate is %.3f Hz" % (os.path.basename(ds["img"]), ((t1 - t0) / (t2 - t1)), 1. / (t2 - t1)))
                r = Rwp(ref, res)
                self.assertTrue(r < 10, "Rwp=%.3f for OpenCL processing of %s" % (r, ds))
Пример #12
0
    def test_correct(self):
        test2d = {
            "numpy": self.eps,
            "cython": self.eps,
            "splitbbox": self.eps,
            "splitpix": self.eps,
            "lut": self.eps,
        }
        if ocl:
            for device in ["cpu", "gpu", "acc"]:
                if ocl.select_device(dtype=device):
                    test2d["lut_ocl_%s" % device] = self.eps
                    test2d["csr_ocl_%s" % device] = self.eps
        test2d_direct = {
            "xrpd2_numpy": 0.3,  # histograms are very noisy in 2D
            "xrpd2_histogram": 0.3,  # histograms are very noisy in 2D
            "xrpd2_splitBBox": self.eps,
            "xrpd2_splitPixel": self.eps
        }

        for meth in test2d:
            logger.info("About to test2d %s" % meth)
            try:
                I, _, _ = self.ai.integrate2d(self.raw,
                                              self.bins,
                                              self.azim,
                                              unit="r_mm",
                                              method=meth,
                                              correctSolidAngle=False,
                                              dark=self.dark,
                                              flat=self.flat)
            except (MemoryError, pyFAI.opencl.pyopencl.MemoryError):
                logger.warning("Got MemoryError from OpenCL device")
                continue
            I = I[numpy.where(I > 0)]
            logger.info("2D method:%s Imin=%s Imax=%s <I>=%s std=%s" %
                        (meth, I.min(), I.max(), I.mean(), I.std()))
            self.assertAlmostEqual(I.mean(), 1, 2,
                                   "Mean should be 1 in %s" % meth)
            self.assert_(
                I.max() - I.min() < test2d[meth],
                "deviation should be small with meth %s, got %s" %
                (meth, I.max() - I.min()))
        for meth in test2d_direct:
            logger.info("About to test2d_direct %s" % meth)
            I, _, _ = self.ai.__getattribute__(meth)(self.raw,
                                                     self.bins,
                                                     self.azim,
                                                     correctSolidAngle=False,
                                                     dark=self.dark,
                                                     flat=self.flat)
            I = I[numpy.where(I > 0)]
            logger.info("1D method:%s Imin=%s Imax=%s <I>=%s std=%s" %
                        (meth, I.min(), I.max(), I.mean(), I.std()))
            self.assert_(
                abs(I.mean() - 1) < test2d_direct[meth],
                "Mean should be 1 in %s" % meth)
            self.assert_(
                I.max() - I.min() < test2d_direct[meth],
                "deviation should be small with meth %s, got %s" %
                (meth, I.max() - I.min()))